Skip to content

Commit

Permalink
[Routing] added a proper exception when a route pattern references th…
Browse files Browse the repository at this point in the history
…e same variable more than once (closes #3344)
  • Loading branch information
fabpot committed Feb 14, 2012
1 parent 802fe64 commit ec7fb0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Routing/RouteCompiler.php
Expand Up @@ -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));

This comment has been minimized.

Copy link
@stof

stof Feb 14, 2012

Member

shoudln't it use an exception of the Component instead ? We have component exceptions for the Routing component

}

$variables[] = $var;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Symfony/Tests/Component/Routing/RouteCompilerTest.php
Expand Up @@ -98,4 +98,14 @@ public function provideCompileData()
)),
);
}

/**
* @expectedException \LogicException
*/
public function testRouteWithSameVariableTwice()
{
$route = new Route('/{name}/{name}');

$compiled = $route->compile();
}
}

0 comments on commit ec7fb0b

Please sign in to comment.