[6.x] Implement HTMLSanitizers as a Laravel Manager#19292
Merged
Conversation
📚 Storybook previews@craftcms/ui — open Storybook No changed components detected in this Storybook. resources/js — open Storybook No changed components detected in this Storybook. |
Contributor
There was a problem hiding this comment.
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
HtmlSanitizersregistry implementation withHtmlSanitizerManager(a Laravel Manager) and updated theHtmlSanitizersfacade 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(). |
riasvdv
marked this pull request as ready for review
July 22, 2026 13:08
# Conflicts: # tests/Feature/Field/MarkdownFieldTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
HTMLSanitizers was doing everything manually that Laravel's Manager support class provides.
This brings the service in line with Laravel conventions and how
extendworks.