From ec7fb0bdd688d3227602d4655db889345570ed30 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 14 Feb 2012 11:41:45 +0100 Subject: [PATCH] [Routing] added a proper exception when a route pattern references the same variable more than once (closes #3344) --- src/Symfony/Component/Routing/RouteCompiler.php | 5 +++++ .../Tests/Component/Routing/RouteCompilerTest.php | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Symfony/Component/Routing/RouteCompiler.php b/src/Symfony/Component/Routing/RouteCompiler.php index a09b01695b6e..5cebd224f76b 100644 --- a/src/Symfony/Component/Routing/RouteCompiler.php +++ b/src/Symfony/Component/Routing/RouteCompiler.php @@ -51,6 +51,11 @@ public function compile(Route $route) } $tokens[] = array('variable', $match[0][0][0], $regexp, $var); + + if (in_array($var, $variables)) { + throw new \LogicException(sprintf('Route pattern "%s" cannot reference variable name "%s" more than once.', $route->getPattern(), $var)); + } + $variables[] = $var; } diff --git a/tests/Symfony/Tests/Component/Routing/RouteCompilerTest.php b/tests/Symfony/Tests/Component/Routing/RouteCompilerTest.php index 2ed569afe53a..08120e7848fa 100644 --- a/tests/Symfony/Tests/Component/Routing/RouteCompilerTest.php +++ b/tests/Symfony/Tests/Component/Routing/RouteCompilerTest.php @@ -98,4 +98,14 @@ public function provideCompileData() )), ); } + + /** + * @expectedException \LogicException + */ + public function testRouteWithSameVariableTwice() + { + $route = new Route('/{name}/{name}'); + + $compiled = $route->compile(); + } }