[Routing] Fix a regression introduced by #4170

This commit is contained in:
Victor Berchet 2012-05-07 18:02:33 +02:00
parent f14961b747
commit 9907df2569
2 changed files with 16 additions and 4 deletions

View File

@ -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);

View File

@ -105,6 +105,14 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array('text', '/foo'),
)),
array(
'Route with a format',
array('/foo/{bar}.{_format}'),
'/foo', '#^/foo/(?<bar>[^/\.]+)\.(?<_format>[^\.]+)$#s', array('bar', '_format'), array(
array('variable', '.', '[^\.]+', '_format'),
array('variable', '/', '[^/\.]+', 'bar'),
array('text', '/foo'),
)),
);
}