Skip to content

Commit

Permalink
Fixed escaping of service identifiers in configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaik Dean authored and fabpot committed Sep 8, 2013
1 parent d05ab6b commit c567262
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
Expand Up @@ -82,7 +82,13 @@ private function addGlobalsSection(ArrayNodeDefinition $rootNode)
->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){
Expand Down
Expand Up @@ -8,6 +8,7 @@
),
'globals' => array(
'foo' => '@bar',
'baz' => '@@qux',
'pi' => 3.14,
'bad' => array('key' => 'foo'),
),
Expand Down
Expand Up @@ -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>
Expand Down
Expand Up @@ -4,6 +4,7 @@ twig:
- MyBundle::form.html.twig
globals:
foo: "@bar"
baz: "@@qux"
pi: 3.14
bad: {key: foo}
auto_reload: true
Expand Down
Expand Up @@ -63,13 +63,15 @@ public function testLoadFullConfiguration($format)
$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
Expand Down

0 comments on commit c567262

Please sign in to comment.