Skip to content

Commit b40e78c

Browse files
path,win: fix bug in resolve
Fixes: #54025
1 parent 49a9ba4 commit b40e78c

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

lib/path.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,17 @@ const win32 = {
263263
!isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
264264
j++;
265265
}
266-
if (j === len || j !== last) {
267-
// We matched a UNC root
268-
device =
269-
`\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`;
270-
rootEnd = j;
266+
if ((j === len || j !== last)) {
267+
if (firstPart !== '.') {
268+
// We matched a UNC root
269+
device =
270+
`\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`;
271+
rootEnd = j;
272+
} else {
273+
// We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
274+
device = `\\\\${firstPart}`;
275+
rootEnd = 4;
276+
}
271277
}
272278
}
273279
}

src/path.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,17 @@ std::string PathResolve(Environment* env,
169169
while (j < len && !IsPathSeparator(path[j])) {
170170
j++;
171171
}
172-
if (j == len || j != last) {
173-
// We matched a UNC root
174-
device = "\\\\" + firstPart + "\\" + path.substr(last, j - last);
175-
rootEnd = j;
172+
if ((j == len || j != last)) {
173+
if (firstPart != ".") {
174+
// We matched a UNC root
175+
device =
176+
"\\\\" + firstPart + "\\" + path.substr(last, j - last);
177+
rootEnd = j;
178+
} else {
179+
// We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
180+
device = "\\\\" + firstPart;
181+
rootEnd = 4;
182+
}
176183
}
177184
}
178185
}

test/cctest/test_path.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ TEST_F(PathTest, PathResolve) {
3939
EXPECT_EQ(
4040
PathResolve(*env, {"C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js"}),
4141
"C:\\foo\\tmp.3\\cycles\\root.js");
42+
EXPECT_EQ(PathResolve(*env, {"\\\\.\\PHYSICALDRIVE0"}),
43+
"\\\\.\\PHYSICALDRIVE0");
4244
#else
4345
EXPECT_EQ(PathResolve(*env, {"/var/lib", "../", "file/"}), "/var/file");
4446
EXPECT_EQ(PathResolve(*env, {"/var/lib", "/../", "file/"}), "/file");

test/parallel/test-path-resolve.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const resolveTests = [
3333
[['c:/', '///some//dir'], 'c:\\some\\dir'],
3434
[['C:\\foo\\tmp.3\\', '..\\tmp.3\\cycles\\root.js'],
3535
'C:\\foo\\tmp.3\\cycles\\root.js'],
36+
[['\\\\.\\PHYSICALDRIVE0'], '\\\\.\\PHYSICALDRIVE0'],
3637
],
3738
],
3839
[ path.posix.resolve,

0 commit comments

Comments
 (0)