Fixed escaping of service identifiers in configuration
This commit is contained in:
parent
d05ab6b940
commit
c567262b7e
@ -82,7 +82,13 @@ class Configuration implements ConfigurationInterface
|
||||
->prototype('array')
|
||||
->beforeNormalization()
|
||||
->ifTrue(function($v){ return is_string($v) && 0 === strpos($v, '@'); })
|
||||
->then(function($v){ return array('id' => substr($v, 1), 'type' => 'service'); })
|
||||
->then(function($v){
|
||||
if (0 === strpos($v, '@@')) {
|
||||
return substr($v, 1);
|
||||
}
|
||||
|
||||
return array('id' => substr($v, 1), 'type' => 'service');
|
||||
})
|
||||
->end()
|
||||
->beforeNormalization()
|
||||
->ifTrue(function($v){
|
||||
|
@ -8,6 +8,7 @@ $container->loadFromExtension('twig', array(
|
||||
),
|
||||
'globals' => array(
|
||||
'foo' => '@bar',
|
||||
'baz' => '@@qux',
|
||||
'pi' => 3.14,
|
||||
'bad' => array('key' => 'foo'),
|
||||
),
|
||||
|
@ -11,6 +11,7 @@
|
||||
<twig:resource>MyBundle::form.html.twig</twig:resource>
|
||||
</twig:form>
|
||||
<twig:global key="foo" id="bar" type="service" />
|
||||
<twig:global key="baz">@@qux</twig:global>
|
||||
<twig:global key="pi">3.14</twig:global>
|
||||
<twig:path>path1</twig:path>
|
||||
<twig:path>path2</twig:path>
|
||||
|
@ -4,6 +4,7 @@ twig:
|
||||
- MyBundle::form.html.twig
|
||||
globals:
|
||||
foo: "@bar"
|
||||
baz: "@@qux"
|
||||
pi: 3.14
|
||||
bad: {key: foo}
|
||||
auto_reload: true
|
||||
|
@ -63,13 +63,15 @@ class TwigExtensionTest extends TestCase
|
||||
$this->assertEquals(new Reference('templating.globals'), $calls[0][1][1]);
|
||||
$this->assertEquals('foo', $calls[1][1][0], '->load() registers services as Twig globals');
|
||||
$this->assertEquals(new Reference('bar'), $calls[1][1][1], '->load() registers services as Twig globals');
|
||||
$this->assertEquals('pi', $calls[2][1][0], '->load() registers variables as Twig globals');
|
||||
$this->assertEquals(3.14, $calls[2][1][1], '->load() registers variables as Twig globals');
|
||||
$this->assertEquals('baz', $calls[2][1][0], '->load() registers variables as Twig globals');
|
||||
$this->assertEquals('@qux', $calls[2][1][1], '->load() allows escaping of service identifiers');
|
||||
$this->assertEquals('pi', $calls[3][1][0], '->load() registers variables as Twig globals');
|
||||
$this->assertEquals(3.14, $calls[3][1][1], '->load() registers variables as Twig globals');
|
||||
|
||||
// Yaml and Php specific configs
|
||||
if (in_array($format, array('yml', 'php'))) {
|
||||
$this->assertEquals('bad', $calls[3][1][0], '->load() registers variables as Twig globals');
|
||||
$this->assertEquals(array('key' => 'foo'), $calls[3][1][1], '->load() registers variables as Twig globals');
|
||||
$this->assertEquals('bad', $calls[4][1][0], '->load() registers variables as Twig globals');
|
||||
$this->assertEquals(array('key' => 'foo'), $calls[4][1][1], '->load() registers variables as Twig globals');
|
||||
}
|
||||
|
||||
// Twig options
|
||||
|
Reference in New Issue
Block a user