Merge branch '2.2' into 2.3

* 2.2:
  [HttpFoundation] fixed regression in the way the request format is handled for duplicated requests (closes #8917)
  [HttpKernel] fixer HInclude src (closes #8951)
  Fixed escaping of service identifiers in configuration
This commit is contained in:
Fabien Potencier 2013-09-08 18:12:21 +02:00
commit a010ed4721
8 changed files with 21 additions and 8 deletions

View File

@ -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){

View File

@ -8,6 +8,7 @@ $container->loadFromExtension('twig', array(
),
'globals' => array(
'foo' => '@bar',
'baz' => '@@qux',
'pi' => 3.14,
'bad' => array('key' => 'foo'),
),

View File

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

View File

@ -4,6 +4,7 @@ twig:
- MyBundle::form.html.twig
globals:
foo: "@bar"
baz: "@@qux"
pi: 3.14
bad: {key: foo}
auto_reload: true

View File

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

View File

@ -405,7 +405,8 @@ class Request
$dup->format = null;
if (!$dup->get('_format')) {
$dup->setRequestFormat($this->getRequestFormat());
// we set the request format to null if the current request is not known
$dup->setRequestFormat($this->getRequestFormat(null));
}
return $dup;

View File

@ -91,7 +91,8 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
throw new \LogicException('You must use a proper URI when using the Hinclude rendering strategy or set a URL signer.');
}
$uri = $this->signer->sign($this->generateFragmentUri($uri, $request));
// we need to sign the absolute URI, but want to return the path only.
$uri = str_replace($request->getSchemeAndHttpHost(), '', $this->signer->sign($this->generateFragmentUri($uri, $request, true)));
}
// We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content.

View File

@ -38,7 +38,7 @@ class HIncludeFragmentRendererTest extends \PHPUnit_Framework_TestCase
{
$strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
$this->assertEquals('<hx:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller&amp;_hash=5RZ1IkwF487EaXt6buHka73CCtQ%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
$this->assertEquals('<hx:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller&amp;_hash=g4b3vtCnhkZBFKrciEFwG7fucVo%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
}
public function testRenderWithUri()