merged branch vicb/route_compiler (PR #4219)

Commits
-------

9907df2 [Routing] Fix a regression introduced by #4170

Discussion
----------

[Routing] Fix a regression introduced by #4170

See 8232aa150b (commitcomment-1300310)

Let's wait to confirm the fix is ok before merging

@stephpy, @mvrhov ?

(Travis is not ok since 5.3.3 is not supported).

---------------------------------------------------------------------------

by stephpy at 2012-05-07T16:17:44Z

Yes it's OK !

Thanks :)

---------------------------------------------------------------------------

by Tobion at 2012-05-07T16:20:38Z

So your originally proposed spec is not the same anymore.

---------------------------------------------------------------------------

by vicb at 2012-05-07T16:22:38Z

@Tobion

* fixed.
* no it is not as it couldn't work in this case.
This commit is contained in:
Fabien Potencier 2012-05-07 19:18:52 +02:00
commit f4fecdfb62
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'),
)),
);
}