Skip to content

Commit 53cad5c

Browse files
committed
[FrameworkBundle] Disable the keys normalization of the CSRF form field attributes
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.
1 parent 06b9c6f commit 53cad5c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

DependencyInjection/Configuration.php

+1
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()

Tests/DependencyInjection/ConfigurationTest.php

+16
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)