Explorar o código

[Routing] fixed the / problem in a URL segment

Fabien Potencier %!s(int64=14) %!d(string=hai) anos
pai
achega
dded1955e4

+ 2 - 2
src/Symfony/Component/Routing/Generator/UrlGenerator.php

@@ -98,8 +98,8 @@ class UrlGenerator implements UrlGeneratorInterface
                         throw new \InvalidArgumentException(sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $requirements[$token[3]], $tparams[$token[3]]));
                     }
 
-                    // %2F is not valid in a URL, so we double encode it
-                    $url = $token[1].str_replace('%2F', '%252F', urlencode($tparams[$token[3]])).$url;
+                    // %2F is not valid in a URL, so we don't encode it (which is fine as the requirements explicitely allowed it)
+                    $url = $token[1].str_replace('%2F', '/', urlencode($tparams[$token[3]])).$url;
                     $optional = false;
                 }
             } elseif ('text' === $token[0]) {

+ 1 - 2
src/Symfony/Component/Routing/Matcher/UrlMatcher.php

@@ -89,8 +89,7 @@ class UrlMatcher implements UrlMatcherInterface
         $parameters = array_merge($this->defaults, $defaults);
         foreach ($params as $key => $value) {
             if (!is_int($key)) {
-                // / are double-encoded as %2F is not valid in a URL (see UrlGenerator)
-                $parameters[$key] = str_replace('%2F', '/', urldecode($value));
+                $parameters[$key] = urldecode($value);
             }
         }