Skip to content

Commit cf6afe3

Browse files
TimothyGuaddaleax
authored andcommitted
url: normalize port on scheme change
PR-URL: #13997 Refs: whatwg/url#328 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent aa4a700 commit cf6afe3

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/internal/url.js

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ function onParseProtocolComplete(flags, protocol, username, password,
238238
ctx.flags &= ~URL_FLAGS_SPECIAL;
239239
}
240240
ctx.scheme = protocol;
241+
ctx.port = port;
241242
}
242243

243244
function onParseHostComplete(flags, protocol, username, password,

src/node_url.cc

+1
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,7 @@ void URL::Parse(const char* input,
12441244
}
12451245

12461246
url->scheme = buffer;
1247+
url->port = NormalizePort(url->scheme, url->port);
12471248
if (new_is_special) {
12481249
url->flags |= URL_FLAGS_SPECIAL;
12491250
special = true;

test/fixtures/url-setter-tests.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
/* WPT Refs:
4-
https://github.com/w3c/web-platform-tests/blob/3eff1bd/url/setters_tests.json
4+
https://github.com/w3c/web-platform-tests/blob/b30abaecf4/url/setters_tests.json
55
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
66
*/
77
module.exports =
@@ -266,6 +266,16 @@ module.exports =
266266
"href": "view-source+data:text/html,<p>Test",
267267
"protocol": "view-source+data:"
268268
}
269+
},
270+
{
271+
"comment": "Port is set to null if it is the default for new scheme.",
272+
"href": "http://foo.com:443/",
273+
"new_value": "https",
274+
"expected": {
275+
"href": "https://foo.com/",
276+
"protocol": "https:",
277+
"port": ""
278+
}
269279
}
270280
],
271281
"username": [

0 commit comments

Comments
 (0)