Skip to content

Commit

Permalink
url: validate argument length in canParse
Browse files Browse the repository at this point in the history
PR-URL: #47513
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
  • Loading branch information
KhafraDev authored and targos committed Nov 10, 2023
1 parent 88f9ebb commit bf4ee17
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,10 @@ class URL {
}

static canParse(url, base = undefined) {
if (arguments.length === 0) {
throw new ERR_MISSING_ARGS('url');
}

url = `${url}`;

if (base !== undefined) {
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-url-canParse-whatwg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

require('../common');
const assert = require('assert');

// One argument is required
assert.throws(() => {
URL.canParse();
}, {
code: 'ERR_MISSING_ARGS',
name: 'TypeError'
});

0 comments on commit bf4ee17

Please sign in to comment.