From 87e7aeb6729f956548c02d7d91da54187aa88f51 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Tue, 17 Sep 2024 19:51:46 -0700 Subject: [PATCH] os: use const with early return for path PR-URL: https://github.com/nodejs/node/pull/54959 Reviewed-By: Luigi Pinca Reviewed-By: Jake Yuesong Li Reviewed-By: Chemi Atlow Reviewed-By: Yagiz Nizipli --- lib/os.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/os.js b/lib/os.js index bbae40b2ab1046..c88ef443b9b4f2 100644 --- a/lib/os.js +++ b/lib/os.js @@ -180,12 +180,13 @@ platform[SymbolToPrimitive] = () => process.platform; */ function tmpdir() { if (isWindows) { - let path = process.env.TEMP || + const path = process.env.TEMP || process.env.TMP || (process.env.SystemRoot || process.env.windir) + '\\temp'; + if (path.length > 1 && StringPrototypeEndsWith(path, '\\') && !StringPrototypeEndsWith(path, ':\\')) - path = StringPrototypeSlice(path, 0, -1); + return StringPrototypeSlice(path, 0, -1); return path; }