From 09d5be8dac5fbc7b8f6d1377ee52f81000dbe7cc Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 6 Nov 2018 21:23:18 +0100 Subject: [PATCH] [Routing] fix dumping conditions that use the request --- .../Component/Routing/Matcher/Dumper/PhpMatcherDumper.php | 2 +- src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 8907fb464fb8..c5cb23c87866 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -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'; } diff --git a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php index c1add96271dc..f1b4314455f5 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php @@ -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'));