Skip to content

[Form][FrameworkBundle][TwigBundle] Add Twig filter, form-type extension and improve service definitions for HtmlSanitizer #46335

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
May 14, 2022

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented May 12, 2022

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR -

This PR borrows the twig filter and the form-type extension from https://github.com/tgalopin/html-sanitizer-bundle/

Given the form builder (the input), it allows doing:

$builder
    ->add('content', TextareaType::class, ['sanitize_html' => true])
;

And on the template side (the output), it allows doing:

<div>
    {{ html|sanitize_html }}
</div>

In order to be able to wire the corresponding services, I had to change the way html-sanitizer is wired by framework-bundle:
What we need here is a default name that we can rely on. By making the default name configurable, the current way to configure html_sanitizer makes it hard for other bundles (twig-bundle here) to know what the default name is. Eg here I would have to make the bundle read the config settings of framework-bundle. I solved this issue by making the default name non-configurable - aka I'm creating a convention: the default name is "default", and this "default" sanitizer is the one aliased to the html_sanitizer service, or to the non-named autowiring alias.

I'm submitting this PR to 6.1 because html-sanitizer is new. If we prefer merging this in 6.2, the updated service wiring must be merged into 6.1 at least.

@carsonbot carsonbot added this to the 6.1 milestone May 12, 2022
@carsonbot carsonbot changed the title [FrameworkBundle][TwigBundle][Form] Add Twig filter, form-type extension and improve service definitions for HtmlSanitizer [Form][FrameworkBundle][TwigBundle] Add Twig filter, form-type extension and improve service definitions for HtmlSanitizer May 12, 2022
Copy link
Contributor

@tgalopin tgalopin left a comment

Choose a reason for hiding this comment

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

Thanks!

(small comment: my email is galopintitouan@gmail.com now 😊)

…ion and improve service definitions for HtmlSanitizer
@nicolas-grekas
Copy link
Member Author

PR is now tested and ready, failures unrelated.

Status: needs review

@fabpot
Copy link
Member

fabpot commented May 14, 2022

Thank you @nicolas-grekas.

@fabpot fabpot merged commit baa367e into symfony:6.1 May 14, 2022
@fabpot fabpot deleted the sanitizer++ branch May 14, 2022 17:10
@fabpot fabpot mentioned this pull request May 14, 2022
fabpot added a commit to twigphp/Twig that referenced this pull request May 15, 2022
This PR was merged into the 2.x branch.

Discussion
----------

Fix support for named closures

As spotted by @stof on symfony/symfony#46335 (comment)

Commits
-------

163f074 Fix support for named closures
}

$sanitizers = $this->sanitizers;
$sanitizer = $options['sanitizer'] ?? $this->defaultSanitizer;
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason not to configure $this->defaultSanitizer as the default value in configureOptions()?

Copy link
Member Author

@nicolas-grekas nicolas-grekas May 17, 2022

Choose a reason for hiding this comment

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

Yes: to make it clear that null means "use the default value". I had removed the possibility to pass null before, and that made it impossible to say so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants