From 2a96ee284cc5aecec9b66d24bddb06acbcc72c98 Mon Sep 17 00:00:00 2001 From: Yichao 'Peak' Ji Date: Thu, 3 May 2018 15:13:25 +0800 Subject: url: fix WHATWG host formatting error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current url.format implementation will return an invalid URL string without the host if there is a port and unicode: true. This unexpected behavior is caused by domainToUnicode, which expects a hostname instead of a host string according to node_url.cc. Adds both a fix and a test for the issue. PR-URL: https://github.com/nodejs/node/pull/20493 Reviewed-By: Michaƫl Zasso Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Anatoli Papirovski Reviewed-By: Trivikram Kamat Reviewed-By: Joyee Cheung Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Ruben Bridgewater Reviewed-By: Daijiro Wachi --- lib/internal/url.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/internal/url.js') diff --git a/lib/internal/url.js b/lib/internal/url.js index cff94e6b7d..d9daef1524 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -400,7 +400,9 @@ Object.defineProperties(URL.prototype, { ret += '@'; } ret += options.unicode ? - domainToUnicode(this.host) : this.host; + domainToUnicode(this.hostname) : this.hostname; + if (ctx.port !== null) + ret += `:${ctx.port}`; } else if (ctx.scheme === 'file:') { ret += '//'; } -- cgit v1.2.3