Browse Source

url: normalize port on scheme change

PR-URL: https://github.com/nodejs/node/pull/13997
Refs: https://github.com/whatwg/url/pull/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>
v6
Timothy Gu 8 years ago
parent
commit
b01ac75edc
No known key found for this signature in database GPG Key ID: 7FE6B095B582B0D4
  1. 1
      lib/internal/url.js
  2. 1
      src/node_url.cc
  3. 12
      test/fixtures/url-setter-tests.js

1
lib/internal/url.js

@ -238,6 +238,7 @@ function onParseProtocolComplete(flags, protocol, username, password,
ctx.flags &= ~URL_FLAGS_SPECIAL; ctx.flags &= ~URL_FLAGS_SPECIAL;
} }
ctx.scheme = protocol; ctx.scheme = protocol;
ctx.port = port;
} }
function onParseHostComplete(flags, protocol, username, password, function onParseHostComplete(flags, protocol, username, password,

1
src/node_url.cc

@ -1244,6 +1244,7 @@ void URL::Parse(const char* input,
} }
url->scheme = buffer; url->scheme = buffer;
url->port = NormalizePort(url->scheme, url->port);
if (new_is_special) { if (new_is_special) {
url->flags |= URL_FLAGS_SPECIAL; url->flags |= URL_FLAGS_SPECIAL;
special = true; special = true;

12
test/fixtures/url-setter-tests.js

@ -1,7 +1,7 @@
'use strict'; 'use strict';
/* WPT Refs: /* 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 License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
*/ */
module.exports = module.exports =
@ -266,6 +266,16 @@ module.exports =
"href": "view-source+data:text/html,<p>Test", "href": "view-source+data:text/html,<p>Test",
"protocol": "view-source+data:" "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": [ "username": [

Loading…
Cancel
Save