Skip to content

Commit 235a272

Browse files
joyeecheungMylesBorins
authored andcommitted
test: test about:blank against invalid WHATWG URL
> If `failure` is true, parsing `about:blank` against `base` > must give failure. This tests that the logic for converting > base URLs into strings properly fails the whole parsing > algorithm if the base URL cannot be parsed. Fixes: #20720 PR-URL: #20796 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent d68f6e6 commit 235a272

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

test/fixtures/url-tests.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/* The following tests are copied from WPT. Modifications to them should be
44
upstreamed first. Refs:
5-
https://github.com/w3c/web-platform-tests/blob/ed4bb727ed/url/urltestdata.json
5+
https://github.com/w3c/web-platform-tests/blob/88b75886e/url/urltestdata.json
66
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
77
*/
88
module.exports =
@@ -6529,27 +6529,34 @@ module.exports =
65296529
"search": "?a",
65306530
"hash": "#%GH"
65316531
},
6532-
"Bad bases",
6532+
"URLs that require a non-about:blank base. (Also serve as invalid base tests.)",
65336533
{
6534-
"input": "test-a.html",
6535-
"base": "a",
6534+
"input": "a",
6535+
"base": "about:blank",
65366536
"failure": true
65376537
},
65386538
{
6539-
"input": "test-a-slash.html",
6540-
"base": "a/",
6539+
"input": "a/",
6540+
"base": "about:blank",
65416541
"failure": true
65426542
},
65436543
{
6544-
"input": "test-a-slash-slash.html",
6545-
"base": "a//",
6544+
"input": "a//",
6545+
"base": "about:blank",
65466546
"failure": true
65476547
},
6548+
"Bases that don't fail to parse but fail to be bases",
65486549
{
65496550
"input": "test-a-colon.html",
65506551
"base": "a:",
65516552
"failure": true
65526553
},
6554+
{
6555+
"input": "test-a-colon-b.html",
6556+
"base": "a:b",
6557+
"failure": true
6558+
},
6559+
"Other base URL tests, that must succeed",
65536560
{
65546561
"input": "test-a-colon-slash.html",
65556562
"base": "a:/",
@@ -6578,11 +6585,6 @@ module.exports =
65786585
"search": "",
65796586
"hash": ""
65806587
},
6581-
{
6582-
"input": "test-a-colon-b.html",
6583-
"base": "a:b",
6584-
"failure": true
6585-
},
65866588
{
65876589
"input": "test-a-colon-slash-b.html",
65886590
"base": "a:/b",

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

+21-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ const fixtures = require('../common/fixtures');
1212

1313
// Tests below are not from WPT.
1414
const tests = require(fixtures.path('url-tests'));
15-
const failureTests = tests.filter((test) => test.failure).concat([
15+
16+
const originalFailures = tests.filter((test) => test.failure);
17+
18+
const typeFailures = [
1619
{ input: '' },
1720
{ input: 'test' },
1821
{ input: undefined },
@@ -25,7 +28,23 @@ const failureTests = tests.filter((test) => test.failure).concat([
2528
{ input: 'test', base: null },
2629
{ input: 'http://nodejs.org', base: null },
2730
{ input: () => {} }
28-
]);
31+
];
32+
33+
// See https://github.com/w3c/web-platform-tests/pull/10955
34+
// > If `failure` is true, parsing `about:blank` against `base`
35+
// > must give failure. This tests that the logic for converting
36+
// > base URLs into strings properly fails the whole parsing
37+
// > algorithm if the base URL cannot be parsed.
38+
const aboutBlankFailures = originalFailures
39+
.map((test) => ({
40+
input: 'about:blank',
41+
base: test.input,
42+
failure: true
43+
}));
44+
45+
const failureTests = originalFailures
46+
.concat(typeFailures)
47+
.concat(aboutBlankFailures);
2948

3049
const expectedError = common.expectsError(
3150
{ code: 'ERR_INVALID_URL', type: TypeError }, failureTests.length);

0 commit comments

Comments
 (0)