Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle] Allow default action in configuration#57653

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Neirda24 wants to merge6 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromNeirda24:feature/57399-html-sanitizer-default-action

Conversation

Neirda24
Copy link
Contributor

@Neirda24Neirda24 commentedJul 4, 2024
edited by OskarStark
Loading

QA
Branch?7.2
Bug fix?no
New feature?yes
Deprecations?no
IssuesFollow-up of#57399 +Fix#48358
LicenseMIT

Seesymfony/symfony-docs#20019 for documentation.

@carsonbotcarsonbot added this to the7.2 milestoneJul 4, 2024
@carsonbotcarsonbot changed the titlefeat(HtmlSanitizer::Config): allow default action from semantic confi…[FrameworkBundle] feat(HtmlSanitizer::Config): allow default action from semantic confi…Jul 4, 2024
Copy link
Member

@xabbuhxabbuh left a comment

Choose a reason for hiding this comment

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

We need to check if the HtmlSanitizer component is present in 7.2+ or issue a meaningful error otherwise.

Neirda24 reacted with thumbs up emoji
@OskarStarkOskarStark changed the title[FrameworkBundle] feat(HtmlSanitizer::Config): allow default action from semantic confi…[FrameworkBundle] feat(HtmlSanitizer::Config): allow default action from semantic configurationJul 4, 2024
@Neirda24
Copy link
ContributorAuthor

@xabbuh : done. However I don't know how to update the test in FrameworkExtensionTest to try with sanitizer <7.2 & >=7.2.

@Neirda24
Copy link
ContributorAuthor

I don't know where and how to fix those errors (related to xml structure). If anyone can point me in the right direction 🙏

@xabbuh
Copy link
Member

@Neirda24 In thesymfony-1.0.xsd file (located insrc/Symfony/Bundle/FrameworkBundle/Resources/config/schema) add<xsd:attribute name="default-action" type="xsd:string" /> as a new entry after line 920.

@Neirda24Neirda24 changed the title[FrameworkBundle] feat(HtmlSanitizer::Config): allow default action from semantic configuration[FrameworkBundle][HtmlSanitizer] Allow default action in configurationJul 9, 2024
@Neirda24Neirda24 requested a review fromxabbuhJuly 9, 2024 18:46
@carsonbotcarsonbot changed the title[FrameworkBundle][HtmlSanitizer] Allow default action in configuration[FrameworkBundle] Allow default action in configurationJul 9, 2024
@@ -2382,6 +2383,10 @@ private function addHtmlSanitizerSection(ArrayNodeDefinition $rootNode, callable
->fixXmlConfig('with_attribute_sanitizer')
->fixXmlConfig('without_attribute_sanitizer')
->children()
->enumNode('default_action')
->info('Defines how the sanitizer must behave by default.')
->values(array_map(static fn (HtmlSanitizerAction $action): string => $action->value, HtmlSanitizerAction::cases()))

Choose a reason for hiding this comment

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

Suggested change
->values(array_map(staticfn (HtmlSanitizerAction$action):string =>$action->value, HtmlSanitizerAction::cases()))
->values(array_column(HtmlSanitizerAction::cases(),'value'))

Copy link
Member

@nicolas-grekasnicolas-grekasJul 10, 2024
edited
Loading

Choose a reason for hiding this comment

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

but this won't work if the component is not installed, isn't it?

Copy link
Member

Choose a reason for hiding this comment

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

Yes good point. Just came here to say#57686 might allow this to be cleaner, but indeed if the enum class is missing what do we do?

Copy link
Member

Choose a reason for hiding this comment

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

Ok so now that#57686 is merged, I would say this could probably be changed to:

->enumNode('default_action')->enumFqcn(HtmlSanitizerAction::class)->end()

The question of what to do when!class_exists(HtmlSanitizerAction::class).. I would say make the enum node conditional, and only declare it if the class exists, so that if html-sanitizer is outdated and you try to configure a default_action the config will error with an unknown option default_action. For better DX we could also if the enum class is not there define it as a dummy null value but throw with a message about html-sanitizer bieng outdated if any value is passed in.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

we might not need to make the enum backed in the end, since we cannot use it to generate the XSD nor the config

@@ -3006,6 +3007,17 @@ private function registerHtmlSanitizerConfiguration(array $config, ContainerBuil
$def = $container->register($configId, HtmlSanitizerConfig::class);

// Base
if ($sanitizerConfig['default_action'] ?? false) {
if (!class_exists(HtmlSanitizerAction::class)) {

Choose a reason for hiding this comment

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

this is dead code because of the way the config is done at the moment: if there is a value, it must be one of the allowed cases, which are derived from the enum

@@ -918,6 +918,7 @@
<xsd:attribute name="allow-relative-links" type="xsd:boolean" />
<xsd:attribute name="allow-relative-medias" type="xsd:boolean" />
<xsd:attribute name="max-input-length" type="xsd:positiveInteger" />
<xsd:attribute name="default-action" type="xsd:string" />

Choose a reason for hiding this comment

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

can't we restrict the possible values to the ones allowed by the enum?

@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpot
Copy link
Member

What's the status of this PR?

@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@SeldaekSeldaekSeldaek left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@xabbuhxabbuhAwaiting requested review from xabbuh

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

[HtmlSanitizer] Add a blockAll helper
6 participants
@Neirda24@xabbuh@fabpot@Seldaek@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp