From 7ca752622b855d8b1b7e1df31a71e0777b3bf690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerhard=20St=C3=B6bich?= <18708370+Flarna@users.noreply.github.com> Date: Fri, 29 Nov 2024 22:28:02 +0100 Subject: [PATCH 1/2] Revert "path,win: fix bug in resolve and normalize" This reverts commit 7f68e5466a9c443d3b19a0a0749debe493a8af34. --- lib/path.js | 41 ++++++++++------------------ src/path.cc | 13 ++------- test/cctest/test_path.cc | 4 --- test/parallel/test-path-makelong.js | 2 +- test/parallel/test-path-normalize.js | 2 -- test/parallel/test-path-resolve.js | 2 -- 6 files changed, 19 insertions(+), 45 deletions(-) diff --git a/lib/path.js b/lib/path.js index 40161c45e2a911..eefa9bc5db0729 100644 --- a/lib/path.js +++ b/lib/path.js @@ -268,16 +268,10 @@ const win32 = { j++; } if (j === len || j !== last) { - if (firstPart !== '.' && 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; - } + // We matched a UNC root + device = + `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`; + rootEnd = j; } } } @@ -387,22 +381,17 @@ const win32 = { !isPathSeparator(StringPrototypeCharCodeAt(path, j))) { j++; } - if (j === len || j !== last) { - if (firstPart === '.' || firstPart === '?') { - // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0) - device = `\\\\${firstPart}`; - rootEnd = 4; - } else if (j === len) { - // We matched a UNC root only - // Return the normalized version of the UNC root since there - // is nothing left to process - return `\\\\${firstPart}\\${StringPrototypeSlice(path, last)}\\`; - } else { - // We matched a UNC root with leftovers - device = - `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`; - rootEnd = j; - } + if (j === len) { + // We matched a UNC root only + // Return the normalized version of the UNC root since there + // is nothing left to process + return `\\\\${firstPart}\\${StringPrototypeSlice(path, last)}\\`; + } + if (j !== last) { + // We matched a UNC root with leftovers + device = + `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`; + rootEnd = j; } } } diff --git a/src/path.cc b/src/path.cc index 1f88e38a857171..5fb745832e492d 100644 --- a/src/path.cc +++ b/src/path.cc @@ -170,16 +170,9 @@ std::string PathResolve(Environment* env, j++; } if (j == len || j != last) { - if (firstPart != "." && 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; - } + // We matched a UNC root + device = "\\\\" + firstPart + "\\" + path.substr(last, j - last); + rootEnd = j; } } } diff --git a/test/cctest/test_path.cc b/test/cctest/test_path.cc index 9e860d02cf77bd..16bd9872f3b035 100644 --- a/test/cctest/test_path.cc +++ b/test/cctest/test_path.cc @@ -39,10 +39,6 @@ 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"); - EXPECT_EQ(PathResolve(*env, {"\\\\?\\PHYSICALDRIVE0"}), - "\\\\?\\PHYSICALDRIVE0"); #else EXPECT_EQ(PathResolve(*env, {"/var/lib", "../", "file/"}), "/var/file"); EXPECT_EQ(PathResolve(*env, {"/var/lib", "/../", "file/"}), "/file"); diff --git a/test/parallel/test-path-makelong.js b/test/parallel/test-path-makelong.js index 4a6589cb6b1a45..7a4783953c8fde 100644 --- a/test/parallel/test-path-makelong.js +++ b/test/parallel/test-path-makelong.js @@ -79,7 +79,7 @@ assert.strictEqual(path.win32.toNamespacedPath('\\\\foo\\bar'), '\\\\?\\UNC\\foo\\bar\\'); assert.strictEqual(path.win32.toNamespacedPath('//foo//bar'), '\\\\?\\UNC\\foo\\bar\\'); -assert.strictEqual(path.win32.toNamespacedPath('\\\\?\\foo'), '\\\\?\\foo'); +assert.strictEqual(path.win32.toNamespacedPath('\\\\?\\foo'), '\\\\?\\foo\\'); assert.strictEqual(path.win32.toNamespacedPath('\\\\?\\c:\\Windows/System'), '\\\\?\\c:\\Windows\\System'); assert.strictEqual(path.win32.toNamespacedPath(null), null); assert.strictEqual(path.win32.toNamespacedPath(true), true); diff --git a/test/parallel/test-path-normalize.js b/test/parallel/test-path-normalize.js index 7a3d02cb7fe126..e1d3b9ce1e6c02 100644 --- a/test/parallel/test-path-normalize.js +++ b/test/parallel/test-path-normalize.js @@ -40,8 +40,6 @@ assert.strictEqual( '..\\..\\..\\..\\baz' ); assert.strictEqual(path.win32.normalize('foo/bar\\baz'), 'foo\\bar\\baz'); -assert.strictEqual(path.win32.normalize('\\\\.\\foo'), '\\\\.\\foo'); -assert.strictEqual(path.win32.normalize('\\\\.\\foo\\'), '\\\\.\\foo\\'); assert.strictEqual(path.posix.normalize('./fixtures///b/../b/c.js'), 'fixtures/b/c.js'); diff --git a/test/parallel/test-path-resolve.js b/test/parallel/test-path-resolve.js index 6b1dfa7567d3d1..3fc9b2e3abd90a 100644 --- a/test/parallel/test-path-resolve.js +++ b/test/parallel/test-path-resolve.js @@ -33,8 +33,6 @@ 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'], - [['\\\\?\\PHYSICALDRIVE0'], '\\\\?\\PHYSICALDRIVE0'], ], ], [ path.posix.resolve, From ccd6228b78da9b55572145fa11e81dc923f4c397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerhard=20St=C3=B6bich?= <18708370+Flarna@users.noreply.github.com> Date: Sat, 30 Nov 2024 00:01:15 +0100 Subject: [PATCH 2/2] test: verify win named pipe enumeration Add a test to verify named pipe enumeration in windows works. --- test/parallel/test-fs-readdir-pipe.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/parallel/test-fs-readdir-pipe.js diff --git a/test/parallel/test-fs-readdir-pipe.js b/test/parallel/test-fs-readdir-pipe.js new file mode 100644 index 00000000000000..6a07b63b479cf0 --- /dev/null +++ b/test/parallel/test-fs-readdir-pipe.js @@ -0,0 +1,21 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const { readdir, readdirSync } = require('fs'); + +if (!common.isWindows) { + common.skip('This test is specific to Windows to test enumerate pipes'); +} + +// Ref: https://github.com/nodejs/node/issues/56002 +// This test is specific to Windows. + +const pipe = '\\\\.\\pipe'; + +assert.ok(readdirSync(pipe).length >= 0); + +readdir(pipe, common.mustCall((err, files) => { + assert.ok(err == null); + assert.ok(files.length >= 0); +}));