From cc6abc6e84b96fd5f1c4123066eba93ddb637e60 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Mon, 12 Mar 2018 15:40:00 +0200 Subject: [PATCH] url: fix error type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently whatwg URLs fail with an incorrect error when null is passed as the base. Adding a check before accessing a symbol for the URL makes the URL error correctly. Add test for it. PR-URL: https://github.com/nodejs/node/pull/19299 Fixes: https://github.com/nodejs/node/issues/19254 Reviewed-By: Colin Ihrig Reviewed-By: Daijiro Wachi Reviewed-By: Ruben Bridgewater Reviewed-By: Michaƫl Zasso Reviewed-By: Luigi Pinca Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell --- lib/internal/url.js | 3 +-- test/parallel/test-whatwg-url-parsing.js | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index 21c7c734b58475..8c83ca86c3fb98 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -319,8 +319,7 @@ class URL { constructor(input, base) { // toUSVString is not needed. input = `${input}`; - if (base !== undefined && - (!base[searchParams] || !base[searchParams][searchParams])) { + if (base !== undefined) { base = new URL(base); } parse(this, input, base); diff --git a/test/parallel/test-whatwg-url-parsing.js b/test/parallel/test-whatwg-url-parsing.js index 928ac5d6a6c658..fd34fee1954d8c 100644 --- a/test/parallel/test-whatwg-url-parsing.js +++ b/test/parallel/test-whatwg-url-parsing.js @@ -22,6 +22,8 @@ const failureTests = tests.filter((test) => test.failure).concat([ { input: null }, { input: new Date() }, { input: new RegExp() }, + { input: 'test', base: null }, + { input: 'http://nodejs.org', base: null }, { input: () => {} } ]);