url: fix error type

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 <cjihrig@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Benjamin Gruenbaum 2018-03-12 15:40:00 +02:00 committed by Ruben Bridgewater
parent b80da63b99
commit cc6abc6e84
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 3 additions and 2 deletions

View File

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

View File

@ -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: () => {} }
]);