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

refactor: whatwg url api #114

Merged
merged 3 commits into from Oct 26, 2019
Merged

refactor: whatwg url api #114

merged 3 commits into from Oct 26, 2019

Conversation

curbengh
Copy link
Contributor

@curbengh curbengh commented Oct 22, 2019

legacy URL api has been deprecated in Node v11; while the API is still available in Node 12, eslint-plugin-node considers it as a deprecated api, thus will emit error if detected.

WHATWG url is actually introduced back in Node v7, thus contrary to my previous PR (hexojs/eslint-config-hexo#19), it is supported in Node 8. The only thing is that Node 8 requires const {URL} = require('url'), whereas newer Node doesn't.

Another noticeable difference is that WHATWG remove the port number if it corresponds to the protocol (e.g. http:80, https:443), which explains the change of port number in the unit test.

decode_url is not refactored to the newer API for now due to a bug in Node 8,

const {format} = require('url')
const bob = new URL('http://user:pass@foo.com:8080/')
console.log(format(bob, { unicode: true }))
// http://user:pass@/
// Domain is removed if port number exists

Once we drop Node 8, not only we can update decode_url, we can also remove const {URL} = require('url') line. It's ok to retain it, but it's not necessary.

WHATWG URL can parse 'foo:bar/baz', thus need an additional check
'url.origin' to ensure it's not an external link
@coveralls
Copy link

coveralls commented Oct 22, 2019

Coverage Status

Coverage increased (+0.08%) to 95.278% when pulling f60127b on curbengh:whatwg-url into b292332 on hexojs:master.

SukkaW
SukkaW previously approved these changes Oct 22, 2019
Copy link
Member

@SukkaW SukkaW left a comment

Choose a reason for hiding this comment

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

LGTM!

@curbengh
Copy link
Contributor Author

Added a test for 4964d80.

@curbengh curbengh requested a review from SukkaW October 23, 2019 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants