Revert "minor #18257 [Routing] Don't needlessly execute strtr's as they are fairly expensive (arjenm)"

This reverts commit f03dc6eec5, reversing
changes made to 2f2ce3e637.
This commit is contained in:
Fabien Potencier 2016-04-28 12:50:58 +02:00
parent e9dda1ee0a
commit 616ebb758f
1 changed files with 9 additions and 16 deletions

View File

@ -75,11 +75,6 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
'%7C' => '|', '%7C' => '|',
); );
/**
* @var string This regexp matches all characters that are not or should not be encoded by rawurlencode (see list in array above).
*/
private $urlEncodingSkipRegexp = '#[^-.~a-zA-Z0-9_/@:;,=+!*|]#';
/** /**
* Constructor. * Constructor.
* *
@ -187,21 +182,19 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
if ('' === $url) { if ('' === $url) {
$url = '/'; $url = '/';
} else if (preg_match($this->urlEncodingSkipRegexp, $url)) {
// the contexts base URL is already encoded (see Symfony\Component\HttpFoundation\Request)
$url = strtr(rawurlencode($url), $this->decodedChars);
} }
// the contexts base URL is already encoded (see Symfony\Component\HttpFoundation\Request)
$url = strtr(rawurlencode($url), $this->decodedChars);
// the path segments "." and ".." are interpreted as relative reference when resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3 // 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 // 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 // otherwise we would generate a URI that, when followed by a user agent (e.g. browser), does not match this route
if(false !== strpos($url, '/.')) { $url = strtr($url, array('/../' => '/%2E%2E/', '/./' => '/%2E/'));
$url = strtr($url, array('/../' => '/%2E%2E/', '/./' => '/%2E/')); if ('/..' === substr($url, -3)) {
if ('/..' === substr($url, -3)) { $url = substr($url, 0, -2).'%2E%2E';
$url = substr($url, 0, -2).'%2E%2E'; } elseif ('/.' === substr($url, -2)) {
} elseif ('/.' === substr($url, -2)) { $url = substr($url, 0, -1).'%2E';
$url = substr($url, 0, -1).'%2E';
}
} }
$schemeAuthority = ''; $schemeAuthority = '';
@ -278,7 +271,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
if ($extra && $query = http_build_query($extra, '', '&')) { if ($extra && $query = http_build_query($extra, '', '&')) {
// "/" and "?" can be left decoded for better user experience, see // "/" and "?" can be left decoded for better user experience, see
// http://tools.ietf.org/html/rfc3986#section-3.4 // http://tools.ietf.org/html/rfc3986#section-3.4
$url .= '?'.(false === strpos($query, '%2F') ? $query : strtr($query, array('%2F' => '/'))); $url .= '?'.strtr($query, array('%2F' => '/'));
} }
return $url; return $url;