URL-encode fewer special characters inside in route parameters #662
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR stops URL-encoding any of the following characters when they appear inside route parameter values:
The issue of (not) encoding parameters originally came up in #118, because
&
wasn't being encoded in the query string and this was breaking parsing of the query, but the solution in #124 (encodeURIComponent()
all parameters) went too far I think—to fix that specific issue it was important to encode query parameters, but not necessarily anything else.A related issue came up in #490, where
mens/blazers
was unintentionally encoded asmens%2Fblazers
, and my fix in #500 specifically skipped encoding/
in certain scenarios.But Laravel's
route()
function actually skips encoding a bunch of special characters in any named route parameters:RouteUrlGenerator
. I'm wondering if we should just do that too.qs
handles encoding/decoding query parameters for us, which isn't affected by this PR, but Laravel actually doesn't encode very much inside actual route parameters.It's important to note here that these URLs are functionally identical whether they're encoded or not. Laravel interprets
a/b
anda%2Fb
exactly the same, regardless of whether they appear in the last route parameter and/or have a wildcard regex explicitly allowing slashes.See #118, #124, #490, #500, #661, and laravel/framework#22125.