Skip to content

Commit

Permalink
url: validate URL constructor arg length
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 4839fc4 commit 180d365
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
4 changes: 4 additions & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,10 @@ class URL {
#searchParams;

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

// toUSVString is not needed.
input = `${input}`;

Expand Down
24 changes: 12 additions & 12 deletions test/parallel/test-url-canParse-whatwg.js
Original file line number Diff line number Diff line change
@@ -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',
});
7 changes: 7 additions & 0 deletions test/parallel/test-whatwg-url-custom-parsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

0 comments on commit 180d365

Please sign in to comment.