From 8952974b5957e746afd3b8ac7a8993d7c87c2e50 Mon Sep 17 00:00:00 2001 From: Sergey Chernyshev Date: Thu, 25 Apr 2024 01:53:28 +0200 Subject: [PATCH] url: validate argument length in canParse PR-URL: https://github.com/nodejs/node/pull/47513 Reviewed-By: Yagiz Nizipli Reviewed-By: Benjamin Gruenbaum Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Luigi Pinca Reviewed-By: Filip Skokan --- graal-nodejs/lib/internal/url.js | 4 ++++ .../test/parallel/test-url-canParse-whatwg.js | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 graal-nodejs/test/parallel/test-url-canParse-whatwg.js diff --git a/graal-nodejs/lib/internal/url.js b/graal-nodejs/lib/internal/url.js index 9c11377aef1..1cb733e1ae2 100644 --- a/graal-nodejs/lib/internal/url.js +++ b/graal-nodejs/lib/internal/url.js @@ -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) { diff --git a/graal-nodejs/test/parallel/test-url-canParse-whatwg.js b/graal-nodejs/test/parallel/test-url-canParse-whatwg.js new file mode 100644 index 00000000000..997c90c343c --- /dev/null +++ b/graal-nodejs/test/parallel/test-url-canParse-whatwg.js @@ -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' +});