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
2024-11-02 18:11:44 +03:00
committed by GitHub
parent 5b9bf39b47
commit 81859cf01f

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;
}