Open domenkozar opened 5 years ago
This bug bit us as well, we were using an email address as a path param and it was working for simple cases, but not when there was a +
in the email address.
This is the spec section for this piece that mentions percent encoding the path segements. https://tools.ietf.org/html/rfc3986#section-3.3
This caused a bug in my code. The behavior directly contradicts the documentation.
Upvote.
This also caused a bug in my code. The part of the documentation that says it escapes is in the function you ultimately need to use to fix your url https://package.elm-lang.org/packages/elm/url/latest/Url#percentEncode
I will say that it DOES escape query parameters... but if you are building an API url for example and some parameters are path params (as they often are) and they contain spaces (as they sometimes do), this bug will get you.
If the proposed fix is to call percentEncode
on all segments, a user from Russia or Denmark might prefer the current behavior. For example:
UB.absolute ["искать", "книги"] []
-- current: "/искать/книги"
-- proposed: "/%D0%B8%D1%81%D0%BA%D0%B0%D1%82%D1%8C/%D0%BA%D0%BD%D0%B8%D0%B3%D0%B8"
UB.absolute ["søg", "bøger"] []
-- current: "/søg/bøger"
-- proposed: "/s%C3%B8g/b%C3%B8ger"
So the current defaults assume that wanting UTF-8 chars in a path is more common than having path segments that contain /
characters. I marked this issue as "breaking" and as a "request" since so many people could have very different opinions on the defaults than the people participating in this thread.
The meta issue #42 attempts to summarize the options and solicit examples and evidence that could inform any future change.
Thought about this: Encode char if char code is lower then 128?
["søg", "bø/ger"].map(a => a.split("").map(v => v.charCodeAt(0) < 128 ? encodeURIComponent(v) : v).join("")).join("/")
Produces:
"søg/bø%2Fger"
should result to
but currently results to
This is especially surprising due to documentation