Skip to content

Commit

Permalink
bug #29113 [Routing] fix dumping conditions that use the request (nic…
Browse files Browse the repository at this point in the history
…olas-grekas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Routing] fix dumping conditions that use the request

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

Commits
-------

09d5be8 [Routing] fix dumping conditions that use the request
  • Loading branch information
nicolas-grekas committed Nov 8, 2018
2 parents 0aa4273 + 09d5be8 commit 626a610
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Expand Up @@ -400,7 +400,7 @@ private function compileRoute(Route $route, string $name, $vars, array &$conditi

if ($condition = $route->getCondition()) {
$condition = $this->getExpressionLanguage()->compile($condition, array('context', 'request'));
$condition = $conditions[$condition] ?? $conditions[$condition] = ((false !== strpos($condition, '$request')) - 1) * \count($conditions);
$condition = $conditions[$condition] ?? $conditions[$condition] = (false !== strpos($condition, '$request') ? 1 : -1) * \count($conditions);
} else {
$condition = 'null';
}
Expand Down
Expand Up @@ -455,6 +455,9 @@ public function testRequestCondition()
{
$coll = new RouteCollection();
$route = new Route('/foo/{bar}');
$route->setCondition('request.getBaseUrl() == "/bar"');
$coll->add('bar', $route);
$route = new Route('/foo/{bar}');
$route->setCondition('request.getBaseUrl() == "/sub/front.php" and request.getPathInfo() == "/foo/bar"');
$coll->add('foo', $route);
$matcher = $this->getUrlMatcher($coll, new RequestContext('/sub/front.php'));
Expand Down

0 comments on commit 626a610

Please sign in to comment.