Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Url Generator and encoding of slashes in query parameters #45114

Copy link
Copy link
Closed
@usu

Description

@usu
Issue body actions

Description

Similar issue as discussed in #13017 and implemented in #39732, however for query parameters and not for path parameters.

I'd like to produce URLs with encoded slashes in query parameters, e.g. expecting an URL like this:

/search?searchPath=%2Fdummy%2Fsearch%2Fpath

I'm aware that slashes in query parameters would be allowed according to RFC3986. Motivation for encoding the slashes is compatibility with another system (to ensure that exactly the same URLs are being generated by both systems).

With the current implementation of UrlGenerator, I'm unable to produce the above expected output. Providing the parameter unencoded will pass the parameter unencoded to the the url. Encoding the parameter before providing to UrlGenerator results in double-encoding:

echo $urlGenerator('search_route', ['searchPath' => '/dummy/search/path']);
// output: /search?searchPath=/dummy/search/path

echo $urlGenerator('search_route', ['searchPath' => rawurlencode('/dummy/search/path')]);
// output: /search?searchPath=%252Fdummy%252Fsearch%252Fpath

The cause for the behavior in the first example is coming from this line:
https://github.com/symfony/routing/blob/c9678d03b147dbd206ec796d25f84a68e398bb2a/Generator/UrlGenerator.php#L310
where '%2F' is decoded back to '/' after encoding it with http_build_query.

In #39732, the same problem was solved by adding a decoding rule for '%252F' => '%2F' to $decodedChars. Would it be thinkable to apply the same fix for QUERY_FRAGMENT_DECODED?

private const QUERY_FRAGMENT_DECODED = [
        // RFC 3986 explicitly allows those in the query/fragment to reference other URIs unencoded
        '%2F' => '/',
        '%252F' => '%2F',
        '%3F' => '?',

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.