Skip to content

Commit 889654d

Browse files
Lxxyxruyadorno
authored andcommitted
url: align url format behavior with browsers
Fixes: #36887 PR-URL: #36903 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
1 parent f589bb2 commit 889654d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/internal/url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ ObjectDefineProperties(URL.prototype, {
437437
ret += '@';
438438
}
439439
ret += options.unicode ?
440-
domainToUnicode(this.hostname) : this.hostname;
440+
domainToUnicode(ctx.host) : ctx.host;
441441
if (ctx.port !== null)
442442
ret += `:${ctx.port}`;
443443
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
6+
{
7+
const url = new (class extends URL { get hostname() { return 'bar.com'; } })('http://foo.com/');
8+
assert.strictEqual(url.href, 'http://foo.com/');
9+
assert.strictEqual(url.toString(), 'http://foo.com/');
10+
assert.strictEqual(url.toJSON(), 'http://foo.com/');
11+
assert.strictEqual(url.hash, '');
12+
assert.strictEqual(url.host, 'foo.com');
13+
assert.strictEqual(url.hostname, 'bar.com');
14+
assert.strictEqual(url.origin, 'http://foo.com');
15+
assert.strictEqual(url.password, '');
16+
assert.strictEqual(url.protocol, 'http:');
17+
assert.strictEqual(url.username, '');
18+
assert.strictEqual(url.search, '');
19+
assert.strictEqual(url.searchParams.toString(), '');
20+
}

0 commit comments

Comments
 (0)