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 <yagiz@nizipli.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
  • Loading branch information
KhafraDev authored and targos committed May 2, 2023
1 parent ede69d2 commit 4839fc4
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 @@ -978,6 +978,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 4839fc4

Please sign in to comment.