8000 feature #26770 Do not normalize array keys in twig globals (lstrojny) · symfony/symfony@3450e47 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3450e47

Browse files
committed
feature #26770 Do not normalize array keys in twig globals (lstrojny)
This PR was merged into the 4.1-dev branch. Discussion ---------- Do not normalize array keys in twig globals | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | rather no | Tests pass? | yes | Fixed tickets | n.A. | License | MIT | Doc PR | n.A. We should leave array keys in twig globals untouched. Commits ------- 8c16727 Don’t normalize global values
2 parents 8c4fd12 + 8c16727 commit 3450e47

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ private function addGlobalsSection(ArrayNodeDefinition $rootNode)
7676
->useAttributeAsKey('key')
7777
->example(array('foo' => '"@bar"', 'pi' => 3.14))
7878
->prototype('array')
79+
->normalizeKeys(false)
7980
->beforeNormalization()
8081
->ifTrue(function ($v) { return is_string($v) && 0 === strpos($v, '@'); })
8182
->then(function ($v) {

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,28 @@ public function testGetStrictVariablesDefaultFalse()
4141

4242
$this->assertFalse($config['strict_variables']);
4343
}
44+
45+
public function testGlobalsAreNotNormalized()
46+
{
47+
$input = array(
48+
'globals' => array('some-global' => true),
49+
);
50+
51+
$processor = new Processor();
52+
$config = $processor->processConfiguration(new Configuration(), array($input));
53+
54+
$this->assertSame(array('some-global' => array('value' => true)), $config['globals']);
55+
}
56+
57+
public function testArrayKeysInGlobalsAreNotNormalized()
58+
{
59+
$input = array(
60+
'globals' => array('global' => array('some-key' => 'some-value')),
61+
);
62+
63+
$processor = new Processor();
64+
$config = $processor->processConfiguration(new Configuration(), array($input));
65+
66+
$this->assertSame(array('global' => array('value' => array('some-key' => 'some-value'))), $config['globals']);
67+
}
4468
}

0 commit comments

Comments
 (0)
0