Repository navigation
assigning a hostname with port 80 to URL.host will not override the existing port #20465
Description
Activity
- addedwhatwg-urlIssues and PRs related to the WHATWG URL implementation.Issues and PRs related to the WHATWG URL implementation.
on May 2, 2018 - addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on May 2, 2018 /cc @nodejs/url
I can see where the problem is in
node_url.ccbut I don't understand enough how the state machine is implemented to fix it.
The port is ignored becauseschemeishttpandportis80, but it doesn't check what the current port is.Refs:
Line 1751 in 9c8b479
url->port = NormalizePort(url->scheme, static_cast<int>(port)); Lines 682 to 687 in 9c8b479
inline int NormalizePort(const std::string& scheme, int p) { #define XX(name, port) if (scheme == name && p == port) return -1; SPECIALS(XX); #undef XX return p; } 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.
Reacted by Domenic DenicolaGot 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
v11.0.0-pre
$ ~/Documents/opensource/node/node test.js
http://some-domain:3000/foo
http://some-domain:3000/foo@eduardbcom There is a typo in OP, the last line should be
console.log(u2.href).my bad, overlooked
Reacted by Vse Mozhe ButyThe 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...).
Reacted by Vse Mozhe Buty and Eduard Bondarenko2 remaining items
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
if (url.port > -1) to
if (url.port > -1 && !IsSpecial(url.scheme.c_str(), url.port))
And add second
isSpecialversion: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,
[03:37|% 100|+ 2240|- 0]: Done.
But of course new tests to cover that are required.@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.
- added a commit that references this issue
on May 15, 2018 - added a commit that references this issue
on May 18, 2018 - added a commit that references this issue
on May 22, 2018
Overriding the host property with a host that has port 80, will not override the port.
Example:
The same bug applies to
httpswith port 443.