diff --git a/src/Symfony/Component/Routing/Route.php b/src/Symfony/Component/Routing/Route.php index 318426a0db..fd9d90dc95 100644 --- a/src/Symfony/Component/Routing/Route.php +++ b/src/Symfony/Component/Routing/Route.php @@ -179,7 +179,7 @@ class Route implements \Serializable * * @param string $name An option name * - * @return mixed The option value + * @return mixed The option value or null when not given */ public function getOption($name) { @@ -236,7 +236,7 @@ class Route implements \Serializable * * @param string $name A variable name * - * @return mixed The default value + * @return mixed The default value or null when not given */ public function getDefault($name) { @@ -323,7 +323,7 @@ class Route implements \Serializable * * @param string $key The key * - * @return string The regex + * @return string|null The regex or null when not given */ public function getRequirement($key) { @@ -352,6 +352,8 @@ class Route implements \Serializable * Compiles the route. * * @return CompiledRoute A CompiledRoute instance + * + * @see RouteCompiler which is responsible for the compilation process */ public function compile() { @@ -371,21 +373,21 @@ class Route implements \Serializable private function sanitizeRequirement($key, $regex) { if (!is_string($regex)) { - throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" must be a string', $key)); + throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" must be a string.', $key)); } - if ('' === $regex) { - throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" cannot be empty', $key)); - } - - if ('^' === $regex[0]) { - $regex = substr($regex, 1); + if ('' !== $regex && '^' === $regex[0]) { + $regex = (string) substr($regex, 1); // returns false for a single character } if ('$' === substr($regex, -1)) { $regex = substr($regex, 0, -1); } + if ('' === $regex) { + throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" cannot be empty.', $key)); + } + return $regex; } } diff --git a/src/Symfony/Component/Routing/Tests/RouteTest.php b/src/Symfony/Component/Routing/Tests/RouteTest.php index 8e466826da..8a42b724f8 100644 --- a/src/Symfony/Component/Routing/Tests/RouteTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteTest.php @@ -112,7 +112,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase { return array( array(''), - array(array()) + array(array()), + array('^$'), + array('^'), + array('$') ); }