From b01ac75edcb68fff860ca131473ea6b985a56493 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Tue, 27 Jun 2017 11:28:24 +0800 Subject: [PATCH] url: normalize port on scheme change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/13997 Refs: https://github.com/whatwg/url/pull/328 Reviewed-By: James M Snell Reviewed-By: Daijiro Wachi Reviewed-By: Michaƫl Zasso --- lib/internal/url.js | 1 + src/node_url.cc | 1 + test/fixtures/url-setter-tests.js | 12 +++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index fc344fbca01cb4..6048777cfd23a5 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -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, diff --git a/src/node_url.cc b/src/node_url.cc index 703ff4ffd61335..2865f445e44606 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -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; diff --git a/test/fixtures/url-setter-tests.js b/test/fixtures/url-setter-tests.js index 42580312c25bc3..923110d9364132 100644 --- a/test/fixtures/url-setter-tests.js +++ b/test/fixtures/url-setter-tests.js @@ -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 = @@ -266,6 +266,16 @@ module.exports = "href": "view-source+data:text/html,

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": [