tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.86k stars 247 forks source link

URL-encode fewer special characters inside in route parameters #662

Closed bakerkretzmar closed 1 year ago

bakerkretzmar commented 1 year ago

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 as mens%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 and a%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.