You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
assigning a hostname with port 80 to URL.host will not override the existing port #20465
Overriding the host property with a host that has port 80, will not override the port.
Example:
const{URL}=require('url')constu=newURL('http://localhost:3000/foo')u.host='some-domain:80'console.log(u.href)// expected http://some-domain:80/foo, actual: http://some-domain:3000/foo // note that any other port besides 80 works correctly:constu2=newURL('http://localhost:3000/foo')u2.host='some-domain:801'console.log(u2.href)// http://some-domain:801/foo
I can see where the problem is in node_url.cc but I don't understand enough how the state machine is implemented to fix it.
The port is ignored because scheme is http and port is 80, but it doesn't check what the current port is.
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?
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.
Activity
targos commentedon May 2, 2018
/cc @nodejs/url
targos commentedon May 2, 2018
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 because
schemeishttpandportis80, but it doesn't check what the current port is.Refs:
node/src/node_url.cc
Line 1751 in 9c8b479
node/src/node_url.cc
Lines 682 to 687 in 9c8b479
AyushG3112 commentedon May 2, 2018
Should the port be overridden unconditionally?
targos commentedon May 2, 2018
Not exactly. In this case, port should be deleted (because the default port for http is 80)
AyushG3112 commentedon May 2, 2018
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?
domenic commentedon May 2, 2018
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.
targos commentedon May 2, 2018
@domenic What happens here is that the port remains at its original value (3000) instead of being set to null.
domenic commentedon May 2, 2018
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.
eduardbme commentedon May 2, 2018
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
vsemozhetbyt commentedon May 2, 2018
@eduardbcom There is a typo in OP, the last line should be
console.log(u2.href).eduardbme commentedon May 2, 2018
my bad, overlooked
AyushG3112 commentedon May 2, 2018
The fix is simple but causing a regression. Trying to figure it out.
giltayar commentedon May 2, 2018
@vsemozhetbyt - the typo is in my bug description, and I fixed it (the typo, not the bug...).
2 remaining items
eduardbme commentedon May 2, 2018
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
node/src/node_url.cc
Line 2031 in 9c8b479
to
And add second
isSpecialversion:No need to change current tests,
[03:37|% 100|+ 2240|- 0]: Done.But of course new tests to cover that are required.
AyushG3112 commentedon May 2, 2018
@eduardbcom The problem with that(I think) will be that the port will be overwritten and not deleted. I tried to do that earlier.
eduardbme commentedon May 2, 2018
@AyushG3112 Please, provide problem example. Thx.
url: introduce `URL_FLAGS_IS_DEFAULT_SCHEME_PORT` flag
url: introduce `URL_FLAGS_IS_DEFAULT_SCHEME_PORT` flag
url: introduce `URL_FLAGS_IS_DEFAULT_SCHEME_PORT` flag