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:
commit
3450e47e78
@ -76,6 +76,7 @@ class Configuration implements ConfigurationInterface
|
|||||||
->useAttributeAsKey('key')
|
->useAttributeAsKey('key')
|
||||||
->example(array('foo' => '"@bar"', 'pi' => 3.14))
|
->example(array('foo' => '"@bar"', 'pi' => 3.14))
|
||||||
->prototype('array')
|
->prototype('array')
|
||||||
|
->normalizeKeys(false)
|
||||||
->beforeNormalization()
|
->beforeNormalization()
|
||||||
->ifTrue(function ($v) { return is_string($v) && 0 === strpos($v, '@'); })
|
->ifTrue(function ($v) { return is_string($v) && 0 === strpos($v, '@'); })
|
||||||
->then(function ($v) {
|
->then(function ($v) {
|
||||||
|
@ -41,4 +41,28 @@ class ConfigurationTest extends TestCase
|
|||||||
|
|
||||||
$this->assertFalse($config['strict_variables']);
|
$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']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user