8000 bug #59829 [FrameworkBundle] Disable the keys normalization of the CS… · symfony/symfony@b7a8ab3 · GitHub
[go: up one dir, main page]

Skip to content

Commit b7a8ab3

Browse files
bug #59829 [FrameworkBundle] Disable the keys normalization of the CSRF form field attributes (sukei)
This PR was merged into the 7.2 branch. Discussion ---------- [FrameworkBundle] Disable the keys normalization of the CSRF form field attributes | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT The form.csrf_protection.field_attr configuration node value should remain as-is when defined. The default behavior of the configuration component is to normalize keys, but in that specific cases, keys becomes HTML attributes and therefore should not be changed. This commit fix that behaviour for the specific node. **Given** ```yaml framework: form: csrf_protection: field_attr: { 'data-example-attr': 'value } ``` **Before this patch** ```php ['field_attr' = ['data_example_attr' => 'value']] ``` **After this patch** ```php ['field_attr' = ['data-example-attr' => 'value']] ``` Commits ------- e73f3bb [FrameworkBundle] Disable the keys normalization of the CSRF form field attributes
2 parents 56820ed + e73f3bb commit b7a8ab3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ private function addFormSection(ArrayNodeDefinition $rootNode, callable $enableI
250250
->scalarNode('field_name')->defaultValue('_token')->end()
251251
->arrayNode('field_attr')
252252
->performNoDeepMerging()
253+
->normalizeKeys(false)
253254
->scalarPrototype()->end()
254255
->defaultValue(['data-controller' => 'csrf-protection'])
255256
->end()

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,22 @@ public function testSerializerJsonDetailedErrorMessagesNotSetByDefaultWithDebugD
699699
$this->assertSame([], $config['serializer']['default_context'] ?? []);
700700
}
701701

702+
public function testFormCsrfProtectionFieldAttrDoNotNormalizeKeys()
703+
{
704+
$processor = new Processor();
705+
$config = $processor->processConfiguration(new Configuration(false), [
706+
[
707+
'form' => [
708+
'csrf_protection' => [
709+
'field_attr' => ['data-example-attr' => 'value'],
710+
],
711+
],
712+
],
713+
]);
714+
715+
$this->assertSame(['data-example-attr' => 'value'], $config['form']['csrf_protection']['field_attr'] ?? []);
716+
}
717+
702718
protected static function getBundleDefaultConfig()
703719
{
704720
return [

0 commit comments

Comments
 (0)
0