-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
assigning a hostname with port 80 to URL.host will not override the existing port #20465
Comments
/cc @nodejs/url |
I can see where the problem is in Refs: Line 1751 in 9c8b479
Lines 682 to 687 in 9c8b479
|
Should the port be overridden unconditionally? |
Not exactly. In this case, port should be deleted (because the default port for http is 80) |
I've been going through the code and will give fixing this a shot in a couple hours if nobody else picks it up first. I believe a test for this would be needed too, right? |
This is per spec I believe, so I don't know why this is tagged confirmed-bug. https://url.spec.whatwg.org/#port-state step 2.1.3. |
@domenic What happens here is that the port remains at its original value (3000) instead of being set to null. |
Got it! Yeah, adding a test to https://github.com/w3c/web-platform-tests/blob/master/url/setters_tests.json#L608 would be great to catch this kind of thing in all implementations. |
checked on master $ ~/Documents/opensource/node/node -v |
@eduardbcom There is a typo in OP, the last line should be |
my bad, overlooked |
The fix is simple but causing a regression. Trying to figure it out. |
@vsemozhetbyt - the typo is in my bug description, and I fixed it (the typo, not the bug...). |
Removing this line fixes the issue: https://github.com/nodejs/node/blob/master/lib/internal/url.js#L279 However, this then introduces a regression in https://github.com/nodejs/node/blob/ef86f2c8524fd65aeda60cad45ea8e3001941cd0/test/parallel/test-whatwg-url-setters.js |
Call `onParsePortComplete` on null port from `onParseHostComplete` to set url’s port to null, if port is url’s scheme’s default port, and to port otherwise, as specified in the spec. Also, trim all trailing `:` from `host` in the setter to fix regressions caused by the change. Refs: https://url.spec.whatwg.org/#port-state Fixes: nodejs#20465
I think in that way we spread URL parse logic between two different parts (js and c++), and that's not good. Much better approach (to my mind) is to make all parse stuff within c++ part, where main logic is placed. So I propose to change Line 2031 in 9c8b479
to if (url.port > -1 && !IsSpecial(url.scheme.c_str(), url.port)) And add second inline bool IsSpecial(const std::string& scheme, const int& p) {
#define XX(name, port) if (scheme == name && p == port) return true;
SPECIALS(XX);
#undef XX
return false;
} No need to change current tests, |
@eduardbcom The problem with that(I think) will be that the port will be overwritten and not deleted. I tried to do that earlier. |
@AyushG3112 Please, provide problem example. Thx. |
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
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>
Overriding the host property with a host that has port 80, will not override the port.
Example:
The same bug applies to
https
with port 443.The text was updated successfully, but these errors were encountered: