elm / url

Build and parse URLs. Useful for HTTP and "routing" in single-page apps (SPAs)
https://package.elm-lang.org/packages/elm/url/latest/
BSD 3-Clause "New" or "Revised" License
75 stars 43 forks source link

Use percentEncode on path segments in Url.Builder #41

Open edkv opened 3 years ago

edkv commented 3 years ago

Example:

> Url.Builder.absolute [ "foo", "/", "bar" ] []
"/foo///bar" : String

Should be /foo%2Fbar, right?

I've seen #21, didn't read the spec, but here's what the Wikipedia article says about this concrete case:

The reserved character /, for example, if used in the "path" component of a URI, has the special meaning of being a delimiter between path segments. If, according to a given URI scheme, / needs to be in a path segment, then the three characters %2F or %2f must be used in the segment instead of a raw /.

I've run across this while debugging an issue in our application with Mapbox search API returning errors on punctuation/special symbols (the URL looks like https://api.mapbox.com/geocoding/v5/mapbox.places/<query>.json).

Augustin82 commented 3 years ago

The same occurs when there are = in a query parameter. I had to use percentEncode and percentDecode manually to work around that issue.