From c5e49e71fc137f6cbce8107b27bd99b639facf02 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 17 May 2018 11:35:28 +0800 Subject: [PATCH 1/2] 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 --- test/fixtures/url-tests.js | 28 +++++++++++++----------- test/parallel/test-whatwg-url-parsing.js | 24 ++++++++++++++++++-- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/test/fixtures/url-tests.js b/test/fixtures/url-tests.js index 745adb8d8aab43..48533ed09073db 100644 --- a/test/fixtures/url-tests.js +++ b/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", diff --git a/test/parallel/test-whatwg-url-parsing.js b/test/parallel/test-whatwg-url-parsing.js index fd34fee1954d8c..e831f2527d2249 100644 --- a/test/parallel/test-whatwg-url-parsing.js +++ b/test/parallel/test-whatwg-url-parsing.js @@ -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,24 @@ 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); From 9a14148a2fa44d0019694cb1fa5dafa4880e21d1 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 17 May 2018 12:30:19 +0800 Subject: [PATCH 2/2] fixup! test: test about:blank against invalid WHATWG URL --- test/parallel/test-whatwg-url-parsing.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/parallel/test-whatwg-url-parsing.js b/test/parallel/test-whatwg-url-parsing.js index e831f2527d2249..fd8570eb720831 100644 --- a/test/parallel/test-whatwg-url-parsing.js +++ b/test/parallel/test-whatwg-url-parsing.js @@ -40,8 +40,7 @@ const aboutBlankFailures = originalFailures input: 'about:blank', base: test.input, failure: true - }) -); + })); const failureTests = originalFailures .concat(typeFailures)