Skip to content

[HtmlSanitizer] fix PHP config examples #18723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions html_sanitizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ attributes from the `W3C Standard Proposal`_ are allowed.
->allowElement('img', 'src')

// allow the <h1> element with all safe attributes
->allowElement('h1')
->allowElement('h1', '*')
;
};

Expand Down Expand Up @@ -611,14 +611,13 @@ This option allows you to disallow attributes that were allowed before.
$framework->htmlSanitizer()
->sanitizer('app.post_sanitizer')
// allow the "data-attr" on all safe elements...
->allowAttribute('data-attr')
->element('*')
->allowAttribute('data-attr', '*')

// ...except for the <section> element
->dropAttribute('data-attr', ['section'])

// disallows "style' on any allowed element
->dropAttribute('style')
->dropAttribute('style', '*')
;
};

Expand All @@ -630,13 +629,13 @@ This option allows you to disallow attributes that were allowed before.
$postSanitizer = new HtmlSanitizer(
(new HtmlSanitizerConfig())
// allow the "data-attr" on all safe elements...
->allowAttribute('data-attr')
->allowAttribute('data-attr', '*')

// ...except for the <section> element
->dropAttribute('data-attr', ['section'])

// disallows "style' on any allowed element
->dropAttribute('style')
->dropAttribute('style', '*')
);

Force Attribute Values
Expand Down Expand Up @@ -688,7 +687,7 @@ element (even if the original one didn't contain a ``rel`` attribute):
return static function (FrameworkConfig $framework): void {
$framework->htmlSanitizer()
->sanitizer('app.post_sanitizer')
->forceAttribute('a', 'rel', 'noopener noreferrer')
->forceAttribute('a', ['rel' => 'noopener noreferrer'])
;
};

Expand Down Expand Up @@ -793,7 +792,7 @@ URLs of ``<a>`` elements:
// specifies the allowed hosts, the attribute will be dropped if the
// URL contains a different host. Subdomains are allowed: e.g. the following
// config would also allow 'www.symfony.com', 'live.symfony.com', etc.
->allowedLinkHost('symfony.com')
->allowedLinkHosts(['symfony.com'])

// whether to allow relative links (i.e. URLs without scheme and host)
->allowRelativeLinks(true)
Expand Down Expand Up @@ -912,7 +911,7 @@ the HTML sanitizer: ``src``, ``href``, ``lowsrc``, ``background`` and ``ping``.

// specifies the allowed hosts, the attribute will be dropped if the URL
// contains a different host which is not a subdomain of the allowed host
->allowedMediaHost('symfony.com') // Also allows any subdomain (i.e. www.symfony.com)
->allowedMediaHosts(['symfony.com']) // Also allows any subdomain (i.e. www.symfony.com)

// whether to allow relative URLs (i.e. URLs without scheme and host)
->allowRelativeMedias(true)
Expand Down