Skip to content

Commit

Permalink
url: validate argument length in canParse
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#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
sercher committed Apr 24, 2024
1 parent 5b0d5cb commit 8952974
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions graal-nodejs/lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,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 graal-nodejs/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'
});

0 comments on commit 8952974

Please sign in to comment.