GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — url: fix WHATWG URL host formatting error caused by port string by peakji · Pull Request #20493 · nodejs/node Conversation
|
|
This is a pretty serious bug and I'm wondering if these ambiguous names (host vs hostname) affected more stuffs in the code base? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
cc @nodejs/url |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The logic needs to be fixed slightly.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ret += options.unicode ? | ||
| domainToUnicode(this.host) : this.host; | ||
| domainToUnicode(this.hostname) : this.hostname; | ||
| if (ctx.port !== '') |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think this should be ctx.port !== null?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The WHATWG URL API uses '' as the empty value, not null.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
> new url.URL("https://nodejs.org/en/") URL { href: 'https://nodejs.org/en/', origin: 'https://nodejs.org', protocol: 'https:', username: '', password: '', host: 'nodejs.org', hostname: 'nodejs.org', port: '', pathname: '/en/', search: '', searchParams: URLSearchParams {}, hash: '' }
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Oh my bad! This is the internal context...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const ctx = this[context]; | ||
| var ret = ctx.scheme; | ||
| if (ctx.host !== null) { | ||
| if (ctx.hostname !== null) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This should also be ctx.host !== null. The hostname change only applies below.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You're right, URLContext uses null:
const { URL } = require('url'); const myURL = new URL('https://nodejs.org/en/'); const kContext = Object.getOwnPropertySymbols(myURL)[0]; console.log(myURL[kContext]);
URLContext {
flags: 400,
scheme: 'https:',
username: '',
password: '',
host: 'nodejs.org',
port: null,
path: [ 'en', '' ],
query: null,
fragment: null }
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
FWIW you might want to contribute your test case back to https://github.com/w3c/web-platform-tests/tree/master/url — clearly this is a case that's not covered by the official tests. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should be good to go now.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Although I agree with this general sentiment, the url.format() API is nonstandard, so it doesn't make sense to test this in the official tests. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Yeah, the Also as the name implies |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@jasnell @nodejs/url I don't know if it makes sense to throw in the non-internal part of our JS API when the non-standard methods like |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Throwing is fine, I think. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
CI re-run for node-test-commit-arm-fanned: https://ci.nodejs.org/job/node-test-commit-arm-fanned/977/ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@joyeecheung I can’t really tell whether your suggestion is something for this PR or not – should we wait with landing this or is it good to go? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@trivikr Could you help me to re-run node-test-commit as well? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@addaleax This PR is good to go, the error handling can be changed in another PR |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Landed in 2a96ee2 Congrats on your first commit in Node.js core and becoming a Contributor! 🎉 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The current url.format implementation will return an invalid URL string without the host if there is a port and unicode: true. This unexpected behavior is caused by domainToUnicode, which expects a hostname instead of a host string according to node_url.cc. Adds both a fix and a test for the issue. PR-URL: #20493 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
The current url.format implementation will return an invalid URL string without the host if there is a port and unicode: true. This unexpected behavior is caused by domainToUnicode, which expects a hostname instead of a host string according to node_url.cc. Adds both a fix and a test for the issue. PR-URL: #20493 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
The current url.format implementation will return an invalid URL string without the host if there is a port and unicode: true. This unexpected behavior is caused by domainToUnicode, which expects a hostname instead of a host string according to node_url.cc. Adds both a fix and a test for the issue. PR-URL: #20493 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
The current url.format implementation will return an invalid URL string without the host if there is a port and unicode: true. This unexpected behavior is caused by domainToUnicode, which expects a hostname instead of a host string according to node_url.cc. Adds both a fix and a test for the issue. PR-URL: #20493 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.