Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2a54965

Browse filesBrowse files
peakjiMylesBorins
authored andcommitted
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 <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>
1 parent 931408e commit 2a54965
Copy full SHA for 2a54965

File tree

Expand file treeCollapse file tree

2 files changed

+8
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+8
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/url.js‎

Copy file name to clipboardExpand all lines: lib/internal/url.js
+3-1Lines changed: 3 additions & 1 deletion
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
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-url-format-whatwg.js
+5Lines changed: 5 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.