Skip to content

Commit

Permalink
url: fix error type
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Benjamin Gruenbaum authored and BridgeAR committed Apr 9, 2018
1 parent b80da63 commit cc6abc6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-whatwg-url-parsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {} }
]);

Expand Down

0 comments on commit cc6abc6

Please sign in to comment.