From 2f4065250e453da2de2ee9cbb8aaae28cbdb4df5 Mon Sep 17 00:00:00 2001 From: DylanTet <100033822+DylanTet@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:26:56 -0800 Subject: [PATCH] url: throw error if argument length of revokeObjectURL is 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added a check to see if url wasn't included as an argument which will then throw an error. Fixes: https://github.com/nodejs/node/issues/50432 PR-URL: https://github.com/nodejs/node/pull/50433 Reviewed-By: James M Snell Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Luigi Pinca Reviewed-By: Zeyu "Alex" Yang --- lib/internal/url.js | 4 ++++ test/parallel/test-url-revokeobjecturl.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test/parallel/test-url-revokeobjecturl.js diff --git a/lib/internal/url.js b/lib/internal/url.js index cdd192daad96d7..38f97926064595 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1108,6 +1108,10 @@ function installObjectURLMethods() { } function revokeObjectURL(url) { + if (arguments.length === 0) { + throw new ERR_MISSING_ARGS('url'); + } + bindingBlob.revokeObjectURL(`${url}`); } diff --git a/test/parallel/test-url-revokeobjecturl.js b/test/parallel/test-url-revokeobjecturl.js new file mode 100644 index 00000000000000..dae980c4d0074c --- /dev/null +++ b/test/parallel/test-url-revokeobjecturl.js @@ -0,0 +1,14 @@ +'use strict'; + +require('../common'); + +// Test ensures that the function receives the url argument. + +const assert = require('node:assert'); + +assert.throws(() => { + URL.revokeObjectURL(); +}, { + code: 'ERR_MISSING_ARGS', + name: 'TypeError', +});