Skip to content

Commit cc6abc6

Browse files
Benjamin GruenbaumBridgeAR
authored andcommitted
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: #19299 Fixes: #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>
1 parent b80da63 commit cc6abc6

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/internal/url.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ class URL {
319319
constructor(input, base) {
320320
// toUSVString is not needed.
321321
input = `${input}`;
322-
if (base !== undefined &&
323-
(!base[searchParams] || !base[searchParams][searchParams])) {
322+
if (base !== undefined) {
324323
base = new URL(base);
325324
}
326325
parse(this, input, base);

test/parallel/test-whatwg-url-parsing.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const failureTests = tests.filter((test) => test.failure).concat([
2222
{ input: null },
2323
{ input: new Date() },
2424
{ input: new RegExp() },
25+
{ input: 'test', base: null },
26+
{ input: 'http://nodejs.org', base: null },
2527
{ input: () => {} }
2628
]);
2729

0 commit comments

Comments
 (0)