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

Improve compatibility with uri-js #84

Merged
merged 10 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function parse (uri, opts) {
parsed.host = unescape(parsed.host)
}
if (parsed.path !== undefined && parsed.path.length) {
parsed.path = encodeURI(parsed.path)
parsed.path = escape(unescape(parsed.path))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate this change?

These functions are deprecated:

> escape(unescape('шеллы'))
'%u0448%u0435%u043B%u043B%u044B'
> encodeURI('шеллы')
'%D1%88%D0%B5%D0%BB%D0%BB%D1%8B'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,

So I want to start by saying that I fully agree with you in that deprecated functions should be avoided in general, but they have different behavior as you pointed out and this change is to achieve url-js compatibility (one of the goals of this library) — you can see that escape and unescape have already been used many times in this file:

fast-uri/index.js

Lines 265 to 274 in bf03d44

if (!schemeHandler || (schemeHandler && !schemeHandler.skipNormalize)) {
if (gotEncoding && parsed.scheme !== undefined) {
parsed.scheme = unescape(parsed.scheme)
}
if (gotEncoding && parsed.userinfo !== undefined) {
parsed.userinfo = unescape(parsed.userinfo)
}
if (gotEncoding && parsed.host !== undefined) {
parsed.host = unescape(parsed.host)
}

In fact, if I recall correctly, someone tried to change these functions to encode/decodeURI, and maybe the tests didn't catch the behavior change for path

Having said all that, I don't think these functions will ever be removed from the Web

}
if (parsed.fragment !== undefined && parsed.fragment.length) {
parsed.fragment = encodeURI(decodeURI(parsed.fragment))
Expand Down
1 change: 1 addition & 0 deletions test/compatibility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test('compatibility Parse', (t) => {
const toParse = [
'//www.g.com/error\n/bleh/bleh',
'https://fastify.org',
'/definitions/Record%3Cstring%2CPerson%3E',
'//10.10.10.10',
'//10.10.000.10',
'//[2001:db8::7%en0]',
Expand Down
Loading