-
Notifications
You must be signed in to change notification settings - Fork 66
Description
I've been writing a wrapper library around this one and it turns out it's not possible to match a url containing anything but english letters. Here is an example url containing a string in Bulgarian:
http://localhost:8000/bg/Тестова-страница
As of Symfony 3.2, the symfony router now officially supports UTF-8 characters in the url. So I assumed symfony-cmf/routing
supports it as well. Unfortunately the link above returns a 404 error.
I did a little digging through the source and found out that the class Symfony\Cmf\Component\Routing\Candidates\Candidates#getCandidates
is causing this issue. The method calls getCandidatesFor($url)
, but the $url
is not being urldecode
d, which is why it fails to find any candidates. Adding a simple urldecode
solves the problem.
/**
* {@inheritdoc}
*/
public function getCandidates(Request $request)
{
$url = urldecode($request->getPathInfo()); // if not decoded, the path here would look like this: /bg/%D0%A2%D0%B5%D1%81%D1%82%D0%BE%D0%B2%D0%B0-%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0
$candidates = $this->getCandidatesFor($url);
$locale = $this->determineLocale($url);
if ($locale) {
$candidates = array_unique(array_merge($candidates, $this->getCandidatesFor(substr($url, strlen($locale) + 1))));
}
return $candidates;
}
I would be happy to open a PR with the fix if there is no better solution.