Skip to content

Commit

Permalink
path,win: fix bug in resolve
Browse files Browse the repository at this point in the history
Fixes: #54025
  • Loading branch information
huseyinacacak-janea committed Aug 6, 2024
1 parent 49a9ba4 commit b40e78c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
16 changes: 11 additions & 5 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,17 @@ const win32 = {
!isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
j++;
}
if (j === len || j !== last) {
// We matched a UNC root
device =
`\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`;
rootEnd = j;
if ((j === len || j !== last)) {
if (firstPart !== '.') {
// We matched a UNC root
device =
`\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`;
rootEnd = j;
} else {
// We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
device = `\\\\${firstPart}`;
rootEnd = 4;
}
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions src/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,17 @@ std::string PathResolve(Environment* env,
while (j < len && !IsPathSeparator(path[j])) {
j++;
}
if (j == len || j != last) {
// We matched a UNC root
device = "\\\\" + firstPart + "\\" + path.substr(last, j - last);
rootEnd = j;
if ((j == len || j != last)) {
if (firstPart != ".") {
// We matched a UNC root
device =
"\\\\" + firstPart + "\\" + path.substr(last, j - last);
rootEnd = j;
} else {
// We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
device = "\\\\" + firstPart;
rootEnd = 4;
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/cctest/test_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ TEST_F(PathTest, PathResolve) {
EXPECT_EQ(
PathResolve(*env, {"C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js"}),
"C:\\foo\\tmp.3\\cycles\\root.js");
EXPECT_EQ(PathResolve(*env, {"\\\\.\\PHYSICALDRIVE0"}),
"\\\\.\\PHYSICALDRIVE0");
#else
EXPECT_EQ(PathResolve(*env, {"/var/lib", "../", "file/"}), "/var/file");
EXPECT_EQ(PathResolve(*env, {"/var/lib", "/../", "file/"}), "/file");
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-path-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const resolveTests = [
[['c:/', '///some//dir'], 'c:\\some\\dir'],
[['C:\\foo\\tmp.3\\', '..\\tmp.3\\cycles\\root.js'],
'C:\\foo\\tmp.3\\cycles\\root.js'],
[['\\\\.\\PHYSICALDRIVE0'], '\\\\.\\PHYSICALDRIVE0'],
],
],
[ path.posix.resolve,
Expand Down

0 comments on commit b40e78c

Please sign in to comment.