Thanks to visit codestin.com
Credit goes to github.com

Skip to content

The router fails to match unicode uri #183

@steve-todorov

Description

@steve-todorov

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 urldecoded, 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions