Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: align url format behavior with browsers #36903

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Lxxyx marked this conversation as resolved.
Show resolved Hide resolved
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(), '');
}