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: https://github.com/nodejs/node/issues/20720

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Joyee Cheung 2018-05-17 11:35:28 +08:00 коммит произвёл Myles Borins
Родитель b6d678b018
Коммит 5886b7826c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 933B01F40B5CA946
2 изменённых файлов: 36 добавлений и 15 удалений

28
test/fixtures/url-tests.js поставляемый
Просмотреть файл

@ -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 =
@ -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:/",
@ -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",

Просмотреть файл

@ -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 },
@ -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);