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

test: test about:blank against invalid WHATWG URL #20796

Closed
wants to merge 2 commits 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
28 changes: 15 additions & 13 deletions test/fixtures/url-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* The following tests are copied from WPT. Modifications to them should be
upstreamed first. Refs:
https://github.com/w3c/web-platform-tests/blob/ed4bb727ed/url/urltestdata.json
https://github.com/w3c/web-platform-tests/blob/88b75886e/url/urltestdata.json
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
*/
module.exports =
Expand Down Expand Up @@ -6529,27 +6529,34 @@ module.exports =
"search": "?a",
"hash": "#%GH"
},
"Bad bases",
"URLs that require a non-about:blank base. (Also serve as invalid base tests.)",
{
"input": "test-a.html",
"base": "a",
"input": "a",
"base": "about:blank",
"failure": true
},
{
"input": "test-a-slash.html",
"base": "a/",
"input": "a/",
"base": "about:blank",
"failure": true
},
{
"input": "test-a-slash-slash.html",
"base": "a//",
"input": "a//",
"base": "about:blank",
"failure": true
},
"Bases that don't fail to parse but fail to be bases",
{
"input": "test-a-colon.html",
"base": "a:",
"failure": true
},
{
"input": "test-a-colon-b.html",
"base": "a:b",
"failure": true
},
"Other base URL tests, that must succeed",
{
"input": "test-a-colon-slash.html",
"base": "a:/",
Expand Down Expand Up @@ -6578,11 +6585,6 @@ module.exports =
"search": "",
"hash": ""
},
{
"input": "test-a-colon-b.html",
"base": "a:b",
"failure": true
},
{
"input": "test-a-colon-slash-b.html",
"base": "a:/b",
Expand Down
23 changes: 21 additions & 2 deletions test/parallel/test-whatwg-url-parsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ const fixtures = require('../common/fixtures');

// Tests below are not from WPT.
const tests = require(fixtures.path('url-tests'));
const failureTests = tests.filter((test) => test.failure).concat([

const originalFailures = tests.filter((test) => test.failure);

const typeFailures = [
{ input: '' },
{ input: 'test' },
{ input: undefined },
Expand All @@ -25,7 +28,23 @@ const failureTests = tests.filter((test) => test.failure).concat([
{ input: 'test', base: null },
{ input: 'http://nodejs.org', base: null },
{ input: () => {} }
]);
];

// See https://github.com/w3c/web-platform-tests/pull/10955
// > 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.
const aboutBlankFailures = originalFailures
.map((test) => ({
input: 'about:blank',
base: test.input,
failure: true
}));

const failureTests = originalFailures
.concat(typeFailures)
.concat(aboutBlankFailures);

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