Skip to content

Commit

Permalink
bug #20687 [FrameworkBundle] Forbid env parameters in routing configu…
Browse files Browse the repository at this point in the history
…ration (nicolas-grekas)

This PR was merged into the 3.2 branch.

Discussion
----------

[FrameworkBundle] Forbid env parameters in routing configuration

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |  #20682
| License       | MIT
| Doc PR        | -

Commits
-------

a931002 [FrameworkBundle] Forbid env parameters in routing configuration
  • Loading branch information
fabpot committed Nov 30, 2016
2 parents 0e12427 + a931002 commit c500a3e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/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 src/Symfony/Bundle/FrameworkBundle/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 c500a3e

Please sign in to comment.