Skip to content

Commit

Permalink
[Routing] use faster approach for encoding rel segments
Browse files Browse the repository at this point in the history
replaced the preg_replace code that was 1.4 times slower than the new code (verified with benchmark
  • Loading branch information
Tobion committed Jul 3, 2012
1 parent 25d326b commit 5c6f848
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Symfony/Component/Routing/Generator/UrlGenerator.php
Expand Up @@ -189,7 +189,12 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
// 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);
Expand Down

0 comments on commit 5c6f848

Please sign in to comment.