From 254e49b47cd6c6b9ce4edd3b6a1e0ecbbfc784df Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 2 Jan 2012 11:45:13 +0100 Subject: [PATCH] [FrameworkBundle] removed the possibility to pass a non-scalar attributes when calling render() to make the call works with or without a reverse proxy (closes #2941) --- CHANGELOG-2.1.md | 1 + src/Symfony/Bundle/FrameworkBundle/HttpKernel.php | 8 ++++++++ .../Bundle/FrameworkBundle/Tests/HttpKernelTest.php | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index 52aa1c7a3be4..629d2233b9f7 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -26,6 +26,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c ### FrameworkBundle + * [BC BREAK] removed the possibility to pass a non-scalar attributes when calling render() to make the call works with or without a reverse proxy * added a router:match command * added kernel.event_subscriber tag * added a way to create relative symlinks when running assets:install command (--relative option) diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php index 1c8fffca677c..8b70f3eaad02 100644 --- a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php @@ -105,6 +105,14 @@ public function render($controller, array $options = array()) 'comment' => '', ), $options); + // enforce all attribute values to be scalars to be sure that the same + // render() call will work with or without a reverse proxy + foreach ($options['attributes'] as $key => $value) { + if (!is_scalar($value)) { + throw new \InvalidArgumentException(sprintf('Unable to render the "%s" controller as the "%s" attribute is not a scalar.', $controller, $key)); + } + } + if (!is_array($options['alt'])) { $options['alt'] = array($options['alt']); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/HttpKernelTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/HttpKernelTest.php index e3eddc5d8574..b0379b26035e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/HttpKernelTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/HttpKernelTest.php @@ -219,4 +219,17 @@ public function testExceptionInSubRequestsDoesNotMangleOutputBuffers() $this->assertEquals('Foo', ob_get_clean()); } + + /** + * @expectedException \InvalidArgumentException + */ + public function testRenderOnlyAllowScalarAttributes() + { + $dispatcher = new EventDispatcher(); + $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface'); + $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $kernel = new HttpKernel($dispatcher, $container, $resolver); + + $kernel->render('/', array('attributes' => array('foo' => new \stdClass()))); + } }