os: improve path check with direct index access

PR-URL: https://github.com/nodejs/node/pull/55434
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
This commit is contained in:
Mert Can Altin authored and Ruy Adorno committed 2024-11-27 11:03:29 -05:00
1 parent 3477b6b4a5
commit 21ec855feb
1 file changed
+2 -3
+2 -3
View File
@@ -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;
}