Skip to content

Url.percentEncode can throw errors #54

@lydell

Description

@lydell

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions