Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: validate argument length in URL and canParse #47513

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 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 Expand Up @@ -978,6 +982,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',
});
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',
});