Skip to content

Commit 2b01138

Browse files
joyeecheungitaloacasas
authored andcommitted
url: TupleOrigin#toString use unicode by default
See: https://url.spec.whatwg.org/#dom-url-origin Also moves the tests for origins to the parsing tests since now URL#origin matches the test cases by default. PR-URL: #10552 Reviewed-By: James M Snell <[email protected]>
1 parent 656ba86 commit 2b01138

File tree

3 files changed

+25
-38
lines changed

3 files changed

+25
-38
lines changed

lib/internal/url.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class TupleOrigin {
6666
return this[kDomain] || this[kHost];
6767
}
6868

69-
toString(unicode = false) {
69+
// https://url.spec.whatwg.org/#dom-url-origin
70+
toString(unicode = true) {
7071
var result = this[kScheme];
7172
result += '://';
7273
result += unicode ? domainToUnicode(this[kHost]) : this[kHost];
@@ -325,7 +326,7 @@ Object.defineProperties(URL.prototype, {
325326
enumerable: true,
326327
configurable: true,
327328
get() {
328-
return originFor(this).toString(true);
329+
return originFor(this).toString();
329330
}
330331
},
331332
protocol: {

test/parallel/test-whatwg-url-origin-for.js

-19
This file was deleted.

test/parallel/test-whatwg-url-parsing.js

+22-17
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,30 @@ const path = require('path');
1313
const assert = require('assert');
1414
const tests = require(path.join(common.fixturesDir, 'url-tests.json'));
1515

16+
function verifyURL(url, test) {
17+
if (test.href) assert.strictEqual(url.href, test.href);
18+
if (test.origin) assert.strictEqual(url.origin, test.origin);
19+
if (test.protocol) assert.strictEqual(url.protocol, test.protocol);
20+
if (test.username) assert.strictEqual(url.username, test.username);
21+
if (test.password) assert.strictEqual(url.password, test.password);
22+
if (test.hostname) assert.strictEqual(url.hostname, test.hostname);
23+
if (test.host) assert.strictEqual(url.host, test.host);
24+
if (test.port !== undefined) assert.strictEqual(url.port, test.port);
25+
if (test.pathname) assert.strictEqual(url.pathname, test.pathname);
26+
if (test.search) assert.strictEqual(url.search, test.search);
27+
if (test.hash) assert.strictEqual(url.hash, test.hash);
28+
}
29+
1630
for (const test of tests) {
1731
if (typeof test === 'string')
1832
continue;
1933

2034
if (test.failure) {
21-
assert.throws(() => new URL(test.input, test.base), /Invalid URL/);
35+
assert.throws(() => new URL(test.input, test.base),
36+
/^TypeError: Invalid URL$/);
2237
} else {
23-
assert.doesNotThrow(() => {
24-
const url = new URL(test.input, test.base);
25-
assert.strictEqual(url.href, test.href);
26-
});
38+
const url = new URL(test.input, test.base);
39+
verifyURL(url, test);
2740
}
2841
}
2942

@@ -115,18 +128,10 @@ const additional_tests = [
115128
}
116129
];
117130

118-
additional_tests.forEach((test) => {
119-
const u = new URL(test.url);
120-
if (test.protocol) assert.strictEqual(test.protocol, u.protocol);
121-
if (test.username) assert.strictEqual(test.username, u.username);
122-
if (test.password) assert.strictEqual(test.password, u.password);
123-
if (test.hostname) assert.strictEqual(test.hostname, u.hostname);
124-
if (test.host) assert.strictEqual(test.host, u.host);
125-
if (test.port !== undefined) assert.strictEqual(test.port, u.port);
126-
if (test.pathname) assert.strictEqual(test.pathname, u.pathname);
127-
if (test.search) assert.strictEqual(test.search, u.search);
128-
if (test.hash) assert.strictEqual(test.hash, u.hash);
129-
});
131+
for (const test of additional_tests) {
132+
const url = new URL(test.url);
133+
verifyURL(url, test);
134+
}
130135

131136
// test inspect
132137
const allTests = additional_tests.slice();

0 commit comments

Comments
 (0)