Skip to content

Commit

Permalink
url: normalize port on scheme change
Browse files Browse the repository at this point in the history
PR-URL: #13997
Refs: whatwg/url#328
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
TimothyGu authored and addaleax committed Jul 18, 2017
1 parent aa4a700 commit cf6afe3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ function onParseProtocolComplete(flags, protocol, username, password,
ctx.flags &= ~URL_FLAGS_SPECIAL;
}
ctx.scheme = protocol;
ctx.port = port;
}

function onParseHostComplete(flags, protocol, username, password,
Expand Down
1 change: 1 addition & 0 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,7 @@ void URL::Parse(const char* input,
}

url->scheme = buffer;
url->port = NormalizePort(url->scheme, url->port);
if (new_is_special) {
url->flags |= URL_FLAGS_SPECIAL;
special = true;
Expand Down
12 changes: 11 additions & 1 deletion test/fixtures/url-setter-tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

/* WPT Refs:
https://github.com/w3c/web-platform-tests/blob/3eff1bd/url/setters_tests.json
https://github.com/w3c/web-platform-tests/blob/b30abaecf4/url/setters_tests.json
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
*/
module.exports =
Expand Down Expand Up @@ -266,6 +266,16 @@ module.exports =
"href": "view-source+data:text/html,<p>Test",
"protocol": "view-source+data:"
}
},
{
"comment": "Port is set to null if it is the default for new scheme.",
"href": "http://foo.com:443/",
"new_value": "https",
"expected": {
"href": "https://foo.com/",
"protocol": "https:",
"port": ""
}
}
],
"username": [
Expand Down

0 comments on commit cf6afe3

Please sign in to comment.