[Routing] use faster approach for encoding rel segments
replaced the preg_replace code that was 1.4 times slower than the new code (verified with benchmark
This commit is contained in:
parent
25d326b55e
commit
5c6f848a7d
@ -189,7 +189,12 @@ class UrlGenerator implements UrlGeneratorInterface
|
||||
// the path segments "." and ".." are interpreted as relative reference when resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3
|
||||
// so we need to encode them as they are not used for this purpose here
|
||||
// otherwise we would generate a URI that, when followed by a user agent (e.g. browser), does not match this route
|
||||
$url = preg_replace(array('#/\.\.(/|$)#', '#/\.(/|$)#'), array('/%2E%2E$1', '/%2E$1'), $url);
|
||||
$url = strtr($url, array('/../' => '/%2E%2E/', '/./' => '/%2E/'));
|
||||
if ('/..' === substr($url, -3)) {
|
||||
$url = substr($url, 0, -2) . '%2E%2E';
|
||||
} elseif ('/.' === substr($url, -2)) {
|
||||
$url = substr($url, 0, -1) . '%2E';
|
||||
}
|
||||
|
||||
// add a query string if needed
|
||||
$extra = array_diff_key($originParameters, $variables, $defaults);
|
||||
|
Reference in New Issue
Block a user