### Install Laravel HTML Sanitizer Source: https://github.com/jeffersongoncalves/laravel-html-sanitizer/blob/master/README.md Install the package via Composer. ```bash composer require jeffersongoncalves/laravel-html-sanitizer ``` -------------------------------- ### Install and publish config for laravel-html-sanitizer Source: https://github.com/jeffersongoncalves/laravel-html-sanitizer/blob/master/resources/boost/skills/html-sanitizer-development/SKILL.md Install the package with Composer. Publish the config file only when you need to adjust the allowlist; the package ships with safe defaults. ```bash composer require jeffersongoncalves/laravel-html-sanitizer ``` ```bash php artisan vendor:publish --tag="html-sanitizer-config" ``` -------------------------------- ### Sanitize HTML with HtmlSanitizer::clean() Source: https://github.com/jeffersongoncalves/laravel-html-sanitizer/blob/master/README.md Sanitize untrusted HTML by passing it through HtmlSanitizer::clean(). The example shows a dirty string with a script and an onerror attribute, and the resulting clean output. ```php use JeffersonGoncalves\HtmlSanitizer\HtmlSanitizer; $dirty = '

Hello

'; $clean = HtmlSanitizer::clean($dirty); //

Hello

``` -------------------------------- ### Run tests, static analysis, and formatting Source: https://github.com/jeffersongoncalves/laravel-html-sanitizer/blob/master/resources/boost/skills/html-sanitizer-development/SKILL.md Run the test suite, static analysis, and code formatting for the project. Use `vendor/bin/pest` for tests, `--coverage` for coverage, `vendor/bin/phpstan analyse` for static analysis, and `vendor/bin/pint` for formatting. ```bash # Run all tests vendor/bin/pest # Run with coverage vendor/bin/pest --coverage # Static analysis vendor/bin/phpstan analyse # Code formatting vendor/bin/pint ``` -------------------------------- ### Configure HtmlSanitizerConfig with default allowlist Source: https://github.com/jeffersongoncalves/laravel-html-sanitizer/blob/master/resources/boost/skills/html-sanitizer-development/SKILL.md Build the default sanitizer configuration. allowSafeElements() enables the curated presentational set; class/id are kept on every element; width/height are scoped to ; data is deliberately excluded from media schemes because a data:image/svg+xml URI can carry executable script. max_input_length defaults to ~2 MB to bound work on a hostile payload; set -1 to disable the cap. Everything not allowed — '); expect($clean) ->not->toContain('toContain('

Hi

'); }); it('strips event handlers', function () { expect(HtmlSanitizer::clean('')) ->not->toContain('onerror'); }); it('strips alpine attributes', function () { expect(HtmlSanitizer::clean('
Menu
')) ->not->toContain('x-data'); }); ``` -------------------------------- ### Assert kept content with HtmlSanitizer::clean Source: https://github.com/jeffersongoncalves/laravel-html-sanitizer/blob/master/resources/boost/skills/html-sanitizer-development/SKILL.md Use this Pest test to verify that the sanitizer preserves safe HTML elements and attributes such as tables, links, image sizing, and class attributes. It asserts that the cleaned output contains the expected safe content. ```php it('keeps tables, links and image sizing', function () { expect(HtmlSanitizer::clean('
1
'))->toContain('1'); expect(HtmlSanitizer::clean('L'))->toContain('href="https://example.com"'); expect(HtmlSanitizer::clean(''))->toContain('width="20%"'); expect(HtmlSanitizer::clean('

Hi

'))->toContain('class="lead"'); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.