Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2b01138

Browse filesBrowse files
joyeecheungItalo A. Casas
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 <jasnell@gmail.com>
1 parent 656ba86 commit 2b01138
Copy full SHA for 2b01138

File tree

Expand file treeCollapse file tree

3 files changed

+25
-38
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-38
lines changed
Open diff view settings
Collapse file

‎lib/internal/url.js‎

Copy file name to clipboardExpand all lines: lib/internal/url.js
+3-2Lines changed: 3 additions & 2 deletions
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: {
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-origin-for.js
-19Lines changed: 0 additions & 19 deletions
This file was deleted.
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-parsing.js
+22-17Lines changed: 22 additions & 17 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.