Skip to content

Fix PHP 8.5 compatibility and harden input sanitization - #20

Merged
rhoerr merged 3 commits into
mage-os:masterfrom
SamueleMartini:php85-compatibility
May 15, 2026
Merged

rhoerr merged 3 commits into
mage-os:masterfrom
SamueleMartini:php85-compatibility

Conversation

@SamueleMartini

@SamueleMartini SamueleMartini commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR makes the module fully compatible with PHP 8.5 while preserving PHP 8.1-8.4 support. Changes focus on:

  • Guarding preg_replace_callback / preg_replace against null subjects (PHP 8.5 emits deprecation notices on implicit null subjects).
  • Hardening Build::sanitizeWidgetParams so all string-sanitization paths go through a single sanitizeStringValue() helper that tolerates non-string input arriving from the request.
  • Loosening Build::isTypeValid to accept mixed input from the POST payload and validate defensively instead of relying on a strict string type hint.
  • Adding missing getCacheKey(): string / getCacheKeyInfo(): array return types on Block\Adminhtml\Widget\Preview\NewWidget to match the parent contract (same fix already applied to ProductsList in 1.4.1).
  • Using typed class constants where safe (HTML_ID_PLACEHOLDER, SCRIPT_REPLACE_REGEX) and consolidating use imports.
  • Declaring the supported PHP range explicitly in composer.json: ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0.
  • CHANGELOG entry for 1.5.0 (2026-04-21).

Files touched

  • composer.json
  • CHANGELOG.md
  • Block/Adminhtml/Widget/Preview/NewWidget.php
  • Block/Adminhtml/Widget/Preview/ProductsList.php
  • Component/Form/WidgetData.php
  • Controller/Adminhtml/ContentType/Widget/Build.php
  • Model/Config/Converter.php
  • Plugin/WidgetContentSettingsCleanup.php

Test plan

  • php -l passes on PHP 8.4 for every changed file (local sanity check).
  • CI on maintainer side for PHP 8.1 / 8.2 / 8.3 / 8.4 / 8.5.
  • Manual smoke test of widget preview in PageBuilder (CMS -> Widgets -> Insert Widget) on an 8.5 stack.

Suggested release

Once merged, I would suggest tagging 1.5.0 (minor bump because the composer.json PHP constraint is broadened and a CHANGELOG entry is added).

cc @rhoerr - opening this against master as a follow-up to the 8.4 PR that already shipped in 1.4.x.

@SamueleMartini
SamueleMartini requested review from a team and dadolun95 as code owners April 21, 2026 17:11
Comment thread Component/Form/WidgetData.php Outdated
@rhoerr

rhoerr commented Apr 30, 2026

Copy link
Copy Markdown
Member

@dadolun95 Can you review this, when time allows?

Comment thread Component/Form/WidgetData.php Outdated
rhoerr and others added 2 commits May 14, 2026 00:19
PHP 8.3+ feature, but composer.json declares 8.1+ support.
Reorder LocalizedException import alphabetically while here.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rhoerr
rhoerr dismissed marcelmtz’s stale review May 15, 2026 00:22

Issue resolved

@rhoerr
rhoerr merged commit af72e68 into mage-os:master May 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants