From 6135fca168f1ddea968aed2acfea5d28194adb83 Mon Sep 17 00:00:00 2001 From: Yichao 'Peak' Ji Date: Thu, 3 May 2018 15:13:25 +0800 Subject: [PATCH 1/4] url: fix WHATWG host formatting error --- lib/internal/url.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index cff94e6b7d2b5b..5672c68ab28576 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -388,7 +388,7 @@ Object.defineProperties(URL.prototype, { }, options); const ctx = this[context]; var ret = ctx.scheme; - if (ctx.host !== null) { + if (ctx.hostname !== null) { ret += '//'; const has_username = ctx.username !== ''; const has_password = ctx.password !== ''; @@ -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 !== '') + ret += `:${ctx.port}` } else if (ctx.scheme === 'file:') { ret += '//'; } From 450272ca7249ca7e65b7d67a7722a640fc9111b6 Mon Sep 17 00:00:00 2001 From: Yichao 'Peak' Ji Date: Thu, 3 May 2018 15:21:09 +0800 Subject: [PATCH 2/4] test: format WHATWG URL with port --- test/parallel/test-url-format-whatwg.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/parallel/test-url-format-whatwg.js b/test/parallel/test-url-format-whatwg.js index 26cef6063c212f..e5c3e369e80390 100644 --- a/test/parallel/test-url-format-whatwg.js +++ b/test/parallel/test-url-format-whatwg.js @@ -111,3 +111,8 @@ assert.strictEqual( url.format(myURL, { unicode: 0 }), 'http://xn--lck1c3crb1723bpq4a.com/a?a=b#c' ); + +assert.strictEqual( + url.format(new URL('http://xn--0zwm56d.com:8080/path'), { unicode: true }), + 'http://测试.com:8080/path' +); From 75f3f68504229e61ab23904aa1d029a94d59b1b3 Mon Sep 17 00:00:00 2001 From: Yichao 'Peak' Ji Date: Thu, 3 May 2018 18:52:12 +0800 Subject: [PATCH 3/4] url: fix the missing semicolon --- lib/internal/url.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index 5672c68ab28576..b1c679a89e4f18 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -402,7 +402,7 @@ Object.defineProperties(URL.prototype, { ret += options.unicode ? domainToUnicode(this.hostname) : this.hostname; if (ctx.port !== '') - ret += `:${ctx.port}` + ret += `:${ctx.port}`; } else if (ctx.scheme === 'file:') { ret += '//'; } From 3db8aacfb1c49adfc36eb52a9503b4b60dc34ec6 Mon Sep 17 00:00:00 2001 From: Yichao 'Peak' Ji Date: Thu, 3 May 2018 19:24:28 +0800 Subject: [PATCH 4/4] url: fix WHATWG formatting logic --- lib/internal/url.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index b1c679a89e4f18..d9daef1524787d 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -388,7 +388,7 @@ Object.defineProperties(URL.prototype, { }, options); const ctx = this[context]; var ret = ctx.scheme; - if (ctx.hostname !== null) { + if (ctx.host !== null) { ret += '//'; const has_username = ctx.username !== ''; const has_password = ctx.password !== ''; @@ -401,7 +401,7 @@ Object.defineProperties(URL.prototype, { } ret += options.unicode ? domainToUnicode(this.hostname) : this.hostname; - if (ctx.port !== '') + if (ctx.port !== null) ret += `:${ctx.port}`; } else if (ctx.scheme === 'file:') { ret += '//';