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 Nov 10, 2023
1 parent bf4ee17 commit 227e749
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 @@ -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();
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 227e749

Please sign in to comment.