Skip to content

Commit

Permalink
[FrameworkBundle] Forbid env parameters in routing configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Nov 29, 2016
1 parent 8a377bb commit 8d80628
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Routing/Router.php
Expand Up @@ -146,6 +146,10 @@ private function resolve($value)
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)) {
Expand Down
14 changes: 14 additions & 0 deletions Tests/Routing/RouterTest.php
Expand Up @@ -131,6 +131,20 @@ public function testPatternPlaceholders()
);
}

/**
* @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();
Expand Down

0 comments on commit 8d80628

Please sign in to comment.