Skip to content

Commit d13fc6e

Browse files
Lxxyxtargos
authored andcommitted
url: align url format behavior with browsers
Fixes: #36887 PR-URL: #36903 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
1 parent e990b11 commit d13fc6e

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎lib/internal/url.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ ObjectDefineProperties(URL.prototype, {
416416
ret+='@';
417417
}
418418
ret+=options.unicode ?
419-
domainToUnicode(this.hostname) : this.hostname;
419+
domainToUnicode(ctx.host) : ctx.host;
420420
if(ctx.port!==null)
421421
ret+=`:${ctx.port}`;
422422
}elseif(ctx.scheme==='file:'){
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
require('../common');
4+
constassert=require('assert');
5+
6+
{
7+
consturl=new(classextendsURL{gethostname(){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)