url: validate argument length in canParse

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Khafra 2023-04-11 11:24:30 -04:00 committed by Node.js GitHub Bot
parent dac8de689b
commit a07caf3f92
2 changed files with 16 additions and 0 deletions

View File

@ -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) {

View File

@ -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'
});