-
Notifications
You must be signed in to change notification settings - Fork 30k
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
url: introduce URL_FLAGS_IS_DEFAULT_SCHEME_PORT
flag
#20479
Conversation
If anyone could suggest where to add tests, that would be great. The fixture used in the existing test is the one provided by W3C and I'm not sure if I should modify that. |
src/node_url.cc
Outdated
@@ -1748,6 +1755,9 @@ void URL::Parse(const char* input, | |||
return; | |||
} | |||
// the port is valid | |||
if (IsDefaultSchemePort(url->scheme, static_cast<int>(port))) { | |||
url->flags |= URL_FLAGS_IS_DEFAULT_SCHEME_PORT; | |||
} | |||
url->port = NormalizePort(url->scheme, static_cast<int>(port)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The job done by IsDefaultSchemePort
is pretty similar to what NormalizePort
does already. Can we instead check url->port == -1
as an indicator for default scheme port?
lib/internal/url.js
Outdated
@@ -270,13 +271,17 @@ function onParseHostnameComplete(flags, protocol, username, password, | |||
|
|||
function onParsePortComplete(flags, protocol, username, password, | |||
host, port, path, query, fragment) { | |||
this[context].port = port; | |||
if ((flags & URL_FLAGS_IS_DEFAULT_SCHEME_PORT) !== 0) { | |||
this[context].port = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case where URL_FLAGS_IS_DEFAULT_SCHEME_PORT
is set, port
should already be null
. Unless I'm missing something there doesn't seem to be a need to have a conditional here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I added the conditional is because the spec explicitly mentions setting the port to null in case of default scheme port.
I can remove it if you think we can just rely on C++ land to send us null
in that situation though.
This PR also lacks tests. Please check out https://github.com/nodejs/node/blob/master/test/fixtures/url-setter-tests.js, add a test in there, and then upstream that test to https://github.com/w3c/web-platform-tests/blob/master/url/setters_tests.json. |
@TimothyGu Fixed. PTAL. Also, to upstream the test, do I just open a PR for https://github.com/w3c/web-platform-tests/blob/master/url/setters_tests.json, or is there any other mechanism? |
/cc @nodejs/url PTAL |
Ping |
@AyushG3112 Yes I think so. |
Test has landed at upstream W3C via web-platform-tests/wpt#10892, and I updated the ordering in |
@jasnell could you please run the CI on this? Also, would this be semver major or patch? Because this fixes a bug but changes the output of an action. |
CI: https://ci.nodejs.org/job/node-test-pull-request/14750/ It's semver-patch :-) |
Do any of the failures look related? |
Failures look unrelated. New try: https://ci.nodejs.org/job/node-test-pull-request/14778/ |
Looks like builds timed out this time. Infra issue? |
Could anyone run the CI on this again please? thanks! |
…d if new port is scheme default, a=testonly Automatic update from web-platform-testsURL: host setter with default port against URL with non-default port See nodejs/node#20479. -- wpt-commits: f0fe4791f5b87491d8d9662832fae543e4edbca1 wpt-pr: 10892
Introduce `URL_FLAGS_IS_DEFAULT_SCHEME_PORT` flag which is retured when the parser detects that the port passed is the default port for that scheme. Fixes: nodejs#20465
PR-URL: nodejs#20479
92051fa
to
70d5dc2
Compare
Rebased to master in hope of CI passing. Can this have another CI run please? |
src/node_url.cc
Outdated
@@ -1749,6 +1749,9 @@ void URL::Parse(const char* input, | |||
} | |||
// the port is valid | |||
url->port = NormalizePort(url->scheme, static_cast<int>(port)); | |||
if (url->port == -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer no curlies, it's the more common style in our C++ code.
src/node_url.h
Outdated
@@ -50,7 +50,8 @@ using v8::Value; | |||
XX(URL_FLAGS_HAS_HOST, 0x80) \ | |||
XX(URL_FLAGS_HAS_PATH, 0x100) \ | |||
XX(URL_FLAGS_HAS_QUERY, 0x200) \ | |||
XX(URL_FLAGS_HAS_FRAGMENT, 0x400) | |||
XX(URL_FLAGS_HAS_FRAGMENT, 0x400) \ | |||
XX(URL_FLAGS_IS_DEFAULT_SCHEME_PORT, 0x800) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the final \
if it doesn't break this. It makes diffs cleaner.
@apapirovski PTAL |
CI: https://ci.nodejs.org/job/node-test-pull-request/14932/ then we land this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reaffirming.
|
@AyushG3112 That one is definitely unrelated. We have a bug in |
@apapirovski what would the next step here be then? Should we wait for the fix to land before landing this, or run the CI on the failed platforms till it is green, or ,assuming |
Introduce `URL_FLAGS_IS_DEFAULT_SCHEME_PORT` flag which is retured when the parser detects that the port passed is the default port for that scheme. PR-URL: nodejs#20479 Fixes: nodejs#20465 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Landed in 11892b0 🎉 |
Introduce `URL_FLAGS_IS_DEFAULT_SCHEME_PORT` flag which is retured when the parser detects that the port passed is the default port for that scheme. PR-URL: #20479 Fixes: #20465 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
…d if new port is scheme default, a=testonly Automatic update from web-platform-testsURL: host setter with default port against URL with non-default port See nodejs/node#20479. -- wpt-commits: f0fe4791f5b87491d8d9662832fae543e4edbca1 wpt-pr: 10892 UltraBlame original commit: 497bd5c8c632f4828e13d82f8c7f0f6d7553126c
…d if new port is scheme default, a=testonly Automatic update from web-platform-testsURL: host setter with default port against URL with non-default port See nodejs/node#20479. -- wpt-commits: f0fe4791f5b87491d8d9662832fae543e4edbca1 wpt-pr: 10892 UltraBlame original commit: 497bd5c8c632f4828e13d82f8c7f0f6d7553126c
…d if new port is scheme default, a=testonly Automatic update from web-platform-testsURL: host setter with default port against URL with non-default port See nodejs/node#20479. -- wpt-commits: f0fe4791f5b87491d8d9662832fae543e4edbca1 wpt-pr: 10892 UltraBlame original commit: 497bd5c8c632f4828e13d82f8c7f0f6d7553126c
Introduce
URL_FLAGS_IS_DEFAULT_SCHEME_PORT
flag which is returedwhen the parser detects that the port passed is the default port
for that scheme.
Fixes: #20465
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes