Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2a54965

Browse files
peakjiMylesBorins
authored andcommittedMay 8, 2018
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: #20493 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
1 parent 931408e commit 2a54965

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
 

‎lib/internal/url.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ Object.defineProperties(URL.prototype, {
400400
ret += '@';
401401
}
402402
ret += options.unicode ?
403-
domainToUnicode(this.host) : this.host;
403+
domainToUnicode(this.hostname) : this.hostname;
404+
if (ctx.port !== null)
405+
ret += `:${ctx.port}`;
404406
} else if (ctx.scheme === 'file:') {
405407
ret += '//';
406408
}

‎test/parallel/test-url-format-whatwg.js

+5
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,8 @@ assert.strictEqual(
111111
url.format(myURL, { unicode: 0 }),
112112
'http://xn--lck1c3crb1723bpq4a.com/a?a=b#c'
113113
);
114+
115+
assert.strictEqual(
116+
url.format(new URL('http://xn--0zwm56d.com:8080/path'), { unicode: true }),
117+
'http://测试.com:8080/path'
118+
);

0 commit comments

Comments
 (0)
Please sign in to comment.