Skip to content

Commit

Permalink
[Routing] fixed the %2f problem in URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Feb 25, 2011
1 parent 1ee6ad4 commit f46c6f7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Symfony/Component/Routing/Generator/UrlGenerator.php
Expand Up @@ -98,7 +98,8 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
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;

This comment has been minimized.

Copy link
@vicb

vicb Feb 25, 2011

Contributor

wouldn't str_ireplace be safer ? (here & below)

$optional = false;
}
} elseif ('text' === $token[0]) {
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Routing/Matcher/UrlMatcher.php
Expand Up @@ -91,7 +91,8 @@ protected function mergeDefaults($params, $defaults)
$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));
}
}

Expand Down

0 comments on commit f46c6f7

Please sign in to comment.