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 authored and Ruben Bridgewater committed 2018-04-10 00:27:09 +02:00
1 parent b80da63b99
commit cc6abc6e84
2 files changed
+3 -2

No files matched your search

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