From 470fd4bdf105ef31b054e528a802454f7c11c06f Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Sat, 2 Nov 2024 18:11:44 +0300 Subject: [PATCH] os: improve path check with direct index access MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/55434 Reviewed-By: Luigi Pinca Reviewed-By: Juan José Arboleda --- lib/os.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/os.js b/lib/os.js index c88ef443b9b4f27..c6e2f220fd223bc 100644 --- a/lib/os.js +++ b/lib/os.js @@ -26,7 +26,6 @@ const { Float64Array, NumberParseInt, ObjectDefineProperties, - StringPrototypeEndsWith, StringPrototypeSlice, SymbolToPrimitive, } = primordials; @@ -184,9 +183,9 @@ function tmpdir() { process.env.TMP || (process.env.SystemRoot || process.env.windir) + '\\temp'; - if (path.length > 1 && StringPrototypeEndsWith(path, '\\') && - !StringPrototypeEndsWith(path, ':\\')) + if (path.length > 1 && path[path.length - 1] === '\\' && path[path.length - 2] !== ':') { return StringPrototypeSlice(path, 0, -1); + } return path; }