Skip to content

[6.x] Implement HTMLSanitizers as a Laravel Manager#19292

Merged
brandonkelly merged 3 commits into
6.xfrom
feature/htmlsanitizer-manager
Jul 22, 2026
Merged

[6.x] Implement HTMLSanitizers as a Laravel Manager#19292
brandonkelly merged 3 commits into
6.xfrom
feature/htmlsanitizer-manager

Conversation

@riasvdv

@riasvdv riasvdv commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

HTMLSanitizers was doing everything manually that Laravel's Manager support class provides.

This brings the service in line with Laravel conventions and how extend works.

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

📚 Storybook previews

@craftcms/uiopen Storybook

No changed components detected in this Storybook.

resources/jsopen Storybook

No changed components detected in this Storybook.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors Craft’s HTML sanitizer registry to use Laravel’s Illuminate\Support\Manager, replacing the previous manual registration/resolution logic and aligning sanitizer extension with Laravel’s extend()/driver conventions.

Changes:

  • Replaced the legacy HtmlSanitizers registry implementation with HtmlSanitizerManager (a Laravel Manager) and updated the HtmlSanitizers facade to resolve the manager.
  • Updated core, adapter, and test code to use HtmlSanitizers::extend()/sanitize() and Manager semantics (driver caching, forgetDrivers(), etc.).
  • Reworked/expanded unit coverage around Manager behavior and updated documentation accordingly.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
yii2-adapter/tests-laravel/HtmlPurifier/LegacyHtmlPurifierConfigRegistrarTest.php Updates adapter test to use the new manager-based sanitizer service.
yii2-adapter/src/Yii2ServiceProvider.php Uses $this->app->make() instead of the global app() helper for registrar boot.
yii2-adapter/src/HtmlPurifier/LegacyHtmlPurifierConfigRegistrar.php Switches legacy HTMLPurifier config registration to extend() against the manager.
yii2-adapter/legacy/helpers/HtmlPurifier.php Updates deprecated helper to route sanitization through the HtmlSanitizers facade.
tests/Unit/Twig/Extensions/HtmlTwigExtensionTest.php Updates unit test to extend sanitizers via facade/Manager API.
tests/Unit/Support/HtmlSanitizer/HtmlSanitizersTest.php Removes old registry tests that targeted the pre-Manager implementation.
tests/Unit/Support/HtmlSanitizer/HtmlSanitizerManagerTest.php Adds new unit tests validating Manager behavior, caching, extension forms, and error cases.
tests/Unit/Field/Data/MarkdownDataTest.php Updates test to use HtmlSanitizers::extend() for sanitizer setup.
tests/Feature/Http/Controllers/App/RenderControllerTest.php Updates feature test sanitizer setup to use the facade extend().
tests/Feature/Field/MarkdownFieldTest.php Updates sanitizer setup and strengthens assertions using DOM crawling.
tests/.pest/snapshots/Unit/Support/HtmlSanitizer/HtmlSanitizersTest/* Removes snapshots tied to the deleted legacy registry tests.
src/Twig/Extensions/HtmlTwigExtension.php Switches Twig sanitize filter implementation to use the facade.
src/Support/HtmlSanitizer/HtmlSanitizerManager.php Implements the sanitizer registry as a Laravel Manager with supported definition forms.
src/Support/Facades/HtmlSanitizers.php Updates facade accessor/signature docs to point at HtmlSanitizerManager.
src/Http/Controllers/App/RenderController.php Updates request validation to pull sanitizer names from the facade/manager.
src/Field/Markdown.php Updates sanitizer option generation to read names from the facade.
src/Field/Data/MarkdownData.php Switches sanitization execution to the facade.
src/Config/ConfigServiceProvider.php Changes sanitizer-definition loading to read from craft.sanitizers config key.
docs/html-sanitizers.md Updates documentation to describe the Manager-based API and extension formats.
CHANGELOG.md Notes introduction of HtmlSanitizerManager and plugin extension via HtmlSanitizers::extend().

Comment thread src/Config/ConfigServiceProvider.php
Comment thread docs/html-sanitizers.md
Comment thread CHANGELOG.md Outdated
@riasvdv
riasvdv requested a review from brandonkelly July 22, 2026 13:08
@riasvdv
riasvdv marked this pull request as ready for review July 22, 2026 13:08
# Conflicts:
#	tests/Feature/Field/MarkdownFieldTest.php
@brandonkelly
brandonkelly merged commit df03adb into 6.x Jul 22, 2026
7 of 9 checks passed
@brandonkelly
brandonkelly deleted the feature/htmlsanitizer-manager branch July 22, 2026 16:04
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