diff --git a/src/Symfony/Component/Routing/RouteCompiler.php b/src/Symfony/Component/Routing/RouteCompiler.php index 5d35663571..50b90ad953 100644 --- a/src/Symfony/Component/Routing/RouteCompiler.php +++ b/src/Symfony/Component/Routing/RouteCompiler.php @@ -48,10 +48,14 @@ class RouteCompiler implements RouteCompilerInterface if ($req = $route->getRequirement($var)) { $regexp = $req; } else { - // Use the character following the variable as the separator when available - // Use the character preceding the variable otherwise - $separator = $pos !== $len ? $pattern[$pos] : $match[0][0][0]; - $regexp = sprintf('[^%s]+', preg_quote($separator, self::REGEX_DELIMITER)); + // Use the character preceding the variable as a separator + $separators = array($match[0][0][0]); + + if ($pos !== $len) { + // Use the character following the variable as the separator when available + $separators[] = $pattern[$pos]; + } + $regexp = sprintf('[^%s]+', preg_quote(implode('', array_unique($separators)), self::REGEX_DELIMITER)); } $tokens[] = array('variable', $match[0][0][0], $regexp, $var); diff --git a/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php b/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php index c2299975d2..6b90bb3083 100644 --- a/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteCompilerTest.php @@ -105,6 +105,14 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase array('text', '/foo'), )), + array( + 'Route with a format', + array('/foo/{bar}.{_format}'), + '/foo', '#^/foo/(?[^/\.]+)\.(?<_format>[^\.]+)$#s', array('bar', '_format'), array( + array('variable', '.', '[^\.]+', '_format'), + array('variable', '/', '[^/\.]+', 'bar'), + array('text', '/foo'), + )), ); }