Skip to content

Commit a741881

Browse files
Merge branch '2.7' into 2.8
* 2.7: [travis] Disable hirak/prestissimo for deps=low/high tests [HttpFoundation] fix phpdoc of UploadedFile Lower complexity of Form:isValid() skipped dns-sensitive tests when DnsMock is not found [FrameworkBundle] Return the invokable service if its name is the class name [ci] Skip dns-sensitive tests when DnsMock is not found Exclude Bridge\PhpUnit from composer.json by default fixed CS Optimize ReplaceAliasByActualDefinitionPass [Process] use __METHOD__ where applicable [Routing] Don't needlessly execute strtr's as they are fairly expensive
2 parents d7d4a20 + b9925bb commit a741881

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

Generator/UrlGenerator.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
7575
'%7C' => '|',
7676
);
7777

78+
/**
79+
* @var string This regexp matches all characters that are not or should not be encoded by rawurlencode (see list in array above).
80+
*/
81+
private $urlEncodingSkipRegexp = '#[^-.~a-zA-Z0-9_/@:;,=+!*|]#';
82+
7883
/**
7984
* Constructor.
8085
*
@@ -196,19 +201,21 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
196201

197202
if ('' === $url) {
198203
$url = '/';
204+
} elseif (preg_match($this->urlEncodingSkipRegexp, $url)) {
205+
// the context base URL is already encoded (see Symfony\Component\HttpFoundation\Request)
206+
$url = strtr(rawurlencode($url), $this->decodedChars);
199207
}
200208

201-
// the contexts base URL is already encoded (see Symfony\Component\HttpFoundation\Request)
202-
$url = strtr(rawurlencode($url), $this->decodedChars);
203-
204209
// the path segments "." and ".." are interpreted as relative reference when resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3
205210
// so we need to encode them as they are not used for this purpose here
206211
// otherwise we would generate a URI that, when followed by a user agent (e.g. browser), does not match this route
207-
$url = strtr($url, array('/../' => '/%2E%2E/', '/./' => '/%2E/'));
208-
if ('/..' === substr($url, -3)) {
209-
$url = substr($url, 0, -2).'%2E%2E';
210-
} elseif ('/.' === substr($url, -2)) {
211-
$url = substr($url, 0, -1).'%2E';
212+
if (false !== strpos($url, '/.')) {
213+
$url = strtr($url, array('/../' => '/%2E%2E/', '/./' => '/%2E/'));
214+
if ('/..' === substr($url, -3)) {
215+
$url = substr($url, 0, -2).'%2E%2E';
216+
} elseif ('/.' === substr($url, -2)) {
217+
$url = substr($url, 0, -1).'%2E';
218+
}
212219
}
213220

214221
$schemeAuthority = '';
@@ -282,7 +289,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
282289
if ($extra && $query = http_build_query($extra, '', '&')) {
283290
// "/" and "?" can be left decoded for better user experience, see
284291
// http://tools.ietf.org/html/rfc3986#section-3.4
285-
$url .= '?'.strtr($query, array('%2F' => '/'));
292+
$url .= '?'.(false === strpos($query, '%2F') ? $query : strtr($query, array('%2F' => '/')));
286293
}
287294

288295
return $url;

0 commit comments

Comments
 (0)