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

Url.percentEncode can throw errors #54

Open lydell opened 2 years ago

lydell commented 2 years ago

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#description

Note that a URIError will be thrown if one attempts to encode a surrogate which is not part of a high-low pair

> import Url
> Url.percentEncode "\u{d800}"
URIError: URI malformed

Url.percentDecode is already wrapped in try-catch but Url.percentEncode isn’t:

https://github.com/elm/url/blob/4e5ee032515581bf01428d54ee636dd601f4bc90/src/Elm/Kernel/Url.js#L7-L22

Note: I have never encountered this for real. I just noticed this because I went to the MDN page for encodeURIComponent to better learn how it works, and realized this is another way an exception can be thrown in Elm. So I’m reporting this more for documentation and collecting all the weird edge cases.