diff --git a/lib/path.js b/lib/path.js index 2f67c8cadc8bd1..4dc4b8398464d3 100644 --- a/lib/path.js +++ b/lib/path.js @@ -788,7 +788,9 @@ const win32 = { } } } else if (code === 47/*/*/ || code === 92/*\*/) { - return path[0]; + // `path` contains just a path separator, exit early to avoid + // unnecessary work + return path; } for (var i = len - 1; i >= offset; --i) { @@ -1041,7 +1043,7 @@ const win32 = { if (len === 3) { // `path` contains just a drive root, exit early to avoid // unnecessary work - ret.root = ret.dir = path.slice(0, 3); + ret.root = ret.dir = path; return ret; } isAbsolute = true; @@ -1050,7 +1052,7 @@ const win32 = { } else { // `path` contains just a drive root, exit early to avoid // unnecessary work - ret.root = ret.dir = path.slice(0, 2); + ret.root = ret.dir = path; return ret; } } @@ -1058,7 +1060,7 @@ const win32 = { } else if (code === 47/*/*/ || code === 92/*\*/) { // `path` contains just a path separator, exit early to avoid // unnecessary work - ret.root = ret.dir = path[0]; + ret.root = ret.dir = path; return ret; }