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

Fix 'TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters' #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

supermario
Copy link

@supermario supermario commented Jul 6, 2020

It appears most browsers (tested in Firefox, Safari and Chromium[Chrome/Brave]) will url-encode paths automatically if they are not already encoded.

xhr2 doesn't match that behaviour when run in node: using an unencoded URL will result in TypeError [ERR_UNESCAPED_CHARACTERS].

Just adding the encoding line however causes a new issue; already encoded URLs end up being double-encoded, changing the URL incorrectly.

Using native-url instead of url fixes this, as well as removing the dependency on the deprecated Legacy URL API.

It would have of course been better to refactor xhr2 to not use the deprecated API, however this does not appear to be trivial looking at the native-url code – at least, I am not able to do that work presently.

I'm not necessarily expecting this to get merged (I think the fact that xhr2 has no dependencies is pretty nice!), but I figured it might be useful for anyone else that runs into the ERR_UNESCAPED_CHARACTERS issue, or for the project maintainers as they're considering how to deal with the API deprecation.

This probably resolves the issue referenced in #35 .

supermario and others added 2 commits July 6, 2020 18:54
unescaped characters'

It appears most browsers (tested in Firefox, Safari and
Chromium[Chrome/Brave]) will url-encode paths automatically if they are
not already encoded.

`xhr2` doesn't match that behavior when run in node: using an
unencoded URL will result in `TypeError [ERR_UNESCAPED_CHARACTERS]`.

Just adding the encoding line however causes a new issue; already
encoded URLs end up being double-encoded, changing the URL incorrectly.

Using [`native-url`](https://github.com/GoogleChromeLabs/native-url
instead of `url` fixes this, as well as removing the dependency on the
deprecated [Legacy URL
API](https://nodejs.org/api/url.html#url_legacy_url_api).

It would have of course been better to refactor `xhr2` to not use the
deprecated API, however this does not appear to be trivial looking at
the [`native-url`
code](https://github.com/GoogleChromeLabs/native-url/tree/master/src).
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

Successfully merging this pull request may close these issues.

2 participants