diff options
author | Yichao 'Peak' Ji <peakji@users.noreply.github.com> | 2018-05-03 15:13:25 +0800 |
---|---|---|
committer | Anatoli Papirovski <apapirovski@mac.com> | 2018-05-07 10:32:22 +0200 |
commit | 2a96ee284cc5aecec9b66d24bddb06acbcc72c98 (patch) | |
tree | de8ae5c8fa999f26274a715ce11f7b8507c434aa /lib/internal/url.js | |
parent | 8f6ab9f799925da836b6c106ed9a8b3d95a2935f (diff) | |
download | android-node-v8-2a96ee284cc5aecec9b66d24bddb06acbcc72c98.tar.gz android-node-v8-2a96ee284cc5aecec9b66d24bddb06acbcc72c98.tar.bz2 android-node-v8-2a96ee284cc5aecec9b66d24bddb06acbcc72c98.zip |
url: fix WHATWG host formatting error
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 <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Diffstat (limited to 'lib/internal/url.js')
-rw-r--r-- | lib/internal/url.js | 4 |
1 files changed, 3 insertions, 1 deletions
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 += '//'; } |