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
-------

8c1672743d Don’t normalize global values
This commit is contained in:
Fabien Potencier 2018-04-20 05:42:27 +02:00
commit 3450e47e78
2 changed files with 25 additions and 0 deletions

View File

@ -76,6 +76,7 @@ class Configuration implements ConfigurationInterface
->useAttributeAsKey('key')
->example(array('foo' => '"@bar"', 'pi' => 3.14))
->prototype('array')
->normalizeKeys(false)
->beforeNormalization()
->ifTrue(function ($v) { return is_string($v) && 0 === strpos($v, '@'); })
->then(function ($v) {

View File

@ -41,4 +41,28 @@ class ConfigurationTest extends TestCase
$this->assertFalse($config['strict_variables']);
}
public function testGlobalsAreNotNormalized()
{
$input = array(
'globals' => array('some-global' => true),
);
$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), array($input));
$this->assertSame(array('some-global' => array('value' => true)), $config['globals']);
}
public function testArrayKeysInGlobalsAreNotNormalized()
{
$input = array(
'globals' => array('global' => array('some-key' => 'some-value')),
);
$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), array($input));
$this->assertSame(array('global' => array('value' => array('some-key' => 'some-value'))), $config['globals']);
}
}