From 70d5fa6f18e1015625931658e436733db2485cf3 Mon Sep 17 00:00:00 2001 From: Sergey Chernyshev Date: Thu, 25 Apr 2024 01:53:30 +0200 Subject: [PATCH] url: validate URL constructor arg length 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 | 24 +++++++++---------- .../test-whatwg-url-custom-parsing.js | 7 ++++++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/graal-nodejs/lib/internal/url.js b/graal-nodejs/lib/internal/url.js index 1cb733e1ae2..9e26e42b27a 100644 --- a/graal-nodejs/lib/internal/url.js +++ b/graal-nodejs/lib/internal/url.js @@ -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(); diff --git a/graal-nodejs/test/parallel/test-url-canParse-whatwg.js b/graal-nodejs/test/parallel/test-url-canParse-whatwg.js index 997c90c343c..7f7d5d40aa7 100644 --- a/graal-nodejs/test/parallel/test-url-canParse-whatwg.js +++ b/graal-nodejs/test/parallel/test-url-canParse-whatwg.js @@ -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', +}); diff --git a/graal-nodejs/test/parallel/test-whatwg-url-custom-parsing.js b/graal-nodejs/test/parallel/test-whatwg-url-custom-parsing.js index a3532374ca6..905028fee38 100644 --- a/graal-nodejs/test/parallel/test-whatwg-url-custom-parsing.js +++ b/graal-nodejs/test/parallel/test-whatwg-url-custom-parsing.js @@ -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', +});