[FrameworkBundle] Forbid env parameters in routing configuration

This commit is contained in:
Nicolas Grekas 2016-11-29 18:09:44 +01:00
parent bd5af67f08
commit a931002ca2
2 changed files with 18 additions and 0 deletions

View File

@ -146,6 +146,10 @@ class Router extends BaseRouter implements WarmableInterface
return '%%';
}
if (preg_match('/^env\(\w+\)$/', $match[1])) {
throw new RuntimeException(sprintf('Using "%%%s%%" is not allowed in routing configuration.', $match[1]));
}
$resolved = $container->getParameter($match[1]);
if (is_string($resolved) || is_numeric($resolved)) {

View File

@ -131,6 +131,20 @@ class RouterTest extends \PHPUnit_Framework_TestCase
);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Using "%env(FOO)%" is not allowed in routing configuration.
*/
public function testEnvPlaceholders()
{
$routes = new RouteCollection();
$routes->add('foo', new Route('/%env(FOO)%'));
$router = new Router($this->getServiceContainer($routes), 'foo');
$router->getRouteCollection();
}
public function testHostPlaceholders()
{
$routes = new RouteCollection();