Browse Source

[Routing] fixed the %2f problem in URLs

Fabien Potencier 14 years ago
parent
commit
f46c6f7e45

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

@@ -98,7 +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]]));
                     }
 
-                    $url = $token[1].urlencode($tparams[$token[3]]).$url;
+                    // %2F is not valid in a URL, so we double encode it
+                    $url = $token[1].str_replace('%2F', '%252F', urlencode($tparams[$token[3]])).$url;
                     $optional = false;
                 }
             } elseif ('text' === $token[0]) {

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

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