Skip to content

Commit d39e993

Browse files
committed
1 parent 4fe0f82 commit d39e993

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/permission/fs_permission.cc

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@ bool is_tree_granted(
4949
const std::string_view& param) {
5050
std::string resolved_param = node::PathResolve(env, {param});
5151
#ifdef _WIN32
52-
// is UNC file path
53-
if (resolved_param.rfind("\\\\", 0) == 0) {
54-
// return lookup with normalized param
55-
size_t starting_pos = 4; // "\\?\"
56-
if (resolved_param.rfind("\\\\?\\UNC\\") == 0) {
57-
starting_pos += 4; // "UNC\"
58-
}
59-
auto normalized = param.substr(starting_pos);
60-
return granted_tree->Lookup(normalized, true);
52+
// Remove leading "\\?\" from UNC path
53+
if (resolved_param.substr(0, 4) == "\\\\?\\") {
54+
resolved_param.erase(0, 4);
55+
}
56+
57+
// Remove leading "UNC\" from UNC path
58+
if (resolved_param.substr(0, 4) == "UNC\\") {
59+
resolved_param.erase(0, 4);
60+
}
61+
// Remove leading "//" from UNC path
62+
if (resolved_param.substr(0, 2) == "//") {
63+
resolved_param.erase(0, 2);
6164
}
6265
#endif
6366
return granted_tree->Lookup(resolved_param, true);

test/parallel/test-permission-fs-windows-path.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,12 @@ if (!common.isWindows) {
3838
assert.strictEqual(stdout.toString(), 'true\n', stderr.toString());
3939
assert.strictEqual(status, 0);
4040
}
41+
42+
{
43+
const { stdout, status, stderr } = spawnSync(process.execPath, [
44+
'--experimental-permission', '--allow-fs-write', 'C:\\*', '-e',
45+
"console.log(process.permission.has('fs.write', '\\\\\\\\A\\\\C:\\Users'))",
46+
]);
47+
assert.strictEqual(stdout.toString(), 'false\n', stderr.toString());
48+
assert.strictEqual(status, 0);
49+
}

0 commit comments

Comments
 (0)