url: validate URL constructor arg length

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 authored and Michaël Zasso committed 2023-11-10 15:56:46 +01:00
1 parent bf4ee17d18
commit 227e749888
3 files changed
+23 -12

No files matched your search

+4
View File
@@ -623,6 +623,10 @@ function isURL(self) {
class URL {
constructor(input, base = undefined) {
if (arguments.length === 0) {
throw new ERR_MISSING_ARGS('url');
}
// toUSVString is not needed.
input = `${input}`;
this[context] = new URLContext();
+12 -12
View File
@@ -1,12 +1,12 @@
'use strict';
require('../common');
const assert = require('assert');
// One argument is required
assert.throws(() => {
URL.canParse();
}, {
code: 'ERR_MISSING_ARGS',
name: 'TypeError'
});
'use strict';
require('../common');
const assert = require('assert');
// One argument is required
assert.throws(() => {
URL.canParse();
}, {
code: 'ERR_MISSING_ARGS',
name: 'TypeError',
});
@@ -78,3 +78,10 @@ for (const test of additional_tests) {
if (test.search) assert.strictEqual(url.search, test.search);
if (test.hash) assert.strictEqual(url.hash, test.hash);
}
assert.throws(() => {
new URL();
}, {
name: 'TypeError',
code: 'ERR_MISSING_ARGS',
});