Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url.percentEncode can throw errors #54

Open
lydell opened this issue Sep 7, 2022 · 0 comments
Open

Url.percentEncode can throw errors #54

lydell opened this issue Sep 7, 2022 · 0 comments

Comments

@lydell
Copy link

lydell commented Sep 7, 2022

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:

function _Url_percentEncode(string)
{
return encodeURIComponent(string);
}
function _Url_percentDecode(string)
{
try
{
return __Maybe_Just(decodeURIComponent(string));
}
catch (e)
{
return __Maybe_Nothing;
}
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant