From 64c2c2a7ac2e86547d30b26d41084e0bd0ee091f Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:46:46 -0400 Subject: [PATCH] lib: replace string prototype usage with alternatives MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/52440 Reviewed-By: Matteo Collina Reviewed-By: Moshe Atlow Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Benjamin Gruenbaum Reviewed-By: Rafael Gonzaga Reviewed-By: Antoine du Hamel --- lib/internal/options.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/internal/options.js b/lib/internal/options.js index effe3249888efd..5cecdc00e5ce95 100644 --- a/lib/internal/options.js +++ b/lib/internal/options.js @@ -5,6 +5,10 @@ const { getEmbedderOptions: getEmbedderOptionsFromBinding, } = internalBinding('options'); +const { + StringPrototypeSlice, +} = primordials; + let warnOnAllowUnauthorized = true; let optionsMap; @@ -43,8 +47,15 @@ function refreshOptions() { function getOptionValue(optionName) { const options = getCLIOptionsFromBinding(); - if (optionName.startsWith('--no-')) { - const option = options.get('--' + optionName.slice(5)); + if ( + optionName.length > 5 && + optionName[0] === '-' && + optionName[1] === '-' && + optionName[2] === 'n' && + optionName[3] === 'o' && + optionName[4] === '-' + ) { + const option = options.get('--' + StringPrototypeSlice(optionName, 5)); return option && !option.value; } return options.get(optionName)?.value;