Skip to content

Commit

Permalink
url: align url format behavior with browsers
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Lxxyx authored and ruyadorno committed Jan 21, 2021
1 parent f589bb2 commit 889654d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ ObjectDefineProperties(URL.prototype, {
ret += '@';
}
ret += options.unicode ?
domainToUnicode(this.hostname) : this.hostname;
domainToUnicode(ctx.host) : ctx.host;
if (ctx.port !== null)
ret += `:${ctx.port}`;
}
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-whatwg-url-override-hostname.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

require('../common');
const assert = require('assert');

{
const url = new (class extends URL { get hostname() { return 'bar.com'; } })('http://foo.com/');
assert.strictEqual(url.href, 'http://foo.com/');
assert.strictEqual(url.toString(), 'http://foo.com/');
assert.strictEqual(url.toJSON(), 'http://foo.com/');
assert.strictEqual(url.hash, '');
assert.strictEqual(url.host, 'foo.com');
assert.strictEqual(url.hostname, 'bar.com');
assert.strictEqual(url.origin, 'http://foo.com');
assert.strictEqual(url.password, '');
assert.strictEqual(url.protocol, 'http:');
assert.strictEqual(url.username, '');
assert.strictEqual(url.search, '');
assert.strictEqual(url.searchParams.toString(), '');
}

0 comments on commit 889654d

Please sign in to comment.