Skip to content

Commit

Permalink
test: test about:blank against invalid WHATWG URL
Browse files Browse the repository at this point in the history
> 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 <apapirovski@mac.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
joyeecheung committed May 22, 2018
1 parent 1637714 commit a5aad24
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
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

0 comments on commit a5aad24

Please sign in to comment.