Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4efa680

Browse filesBrowse files
committed
permission: handle end nodes with children cases
PR-URL: #48531 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent e50c316 commit 4efa680
Copy full SHA for 4efa680

File tree

Expand file treeCollapse file tree

3 files changed

+16
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-4
lines changed
Open diff view settings
Collapse file

‎src/permission/fs_permission.cc‎

Copy file name to clipboardExpand all lines: src/permission/fs_permission.cc
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ bool FSPermission::RadixTree::Lookup(const std::string_view& s,
132132
if (current_node->children.size() == 0) {
133133
return when_empty_return;
134134
}
135-
136135
unsigned int parent_node_prefix_len = current_node->prefix.length();
137136
const std::string path(s);
138137
auto path_len = path.length();
Collapse file

‎src/permission/fs_permission.h‎

Copy file name to clipboardExpand all lines: src/permission/fs_permission.h
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ class FSPermission final : public PermissionBase {
2525
std::string prefix;
2626
std::unordered_map<char, Node*> children;
2727
Node* wildcard_child;
28+
bool is_leaf;
2829

2930
explicit Node(const std::string& pre)
30-
: prefix(pre), wildcard_child(nullptr) {}
31+
: prefix(pre), wildcard_child(nullptr), is_leaf(false) {}
3132

32-
Node() : wildcard_child(nullptr) {}
33+
Node() : wildcard_child(nullptr), is_leaf(false) {}
3334

3435
Node* CreateChild(std::string prefix) {
36+
if (prefix.empty() && !is_leaf) {
37+
is_leaf = true;
38+
return this;
39+
}
3540
char label = prefix[0];
3641

3742
Node* child = children[label];
@@ -56,6 +61,7 @@ class FSPermission final : public PermissionBase {
5661
return split_child->CreateChild(prefix.substr(i));
5762
}
5863
}
64+
child->is_leaf = true;
5965
return child->CreateChild(prefix.substr(i));
6066
}
6167

@@ -114,7 +120,7 @@ class FSPermission final : public PermissionBase {
114120
if (children.size() == 0) {
115121
return true;
116122
}
117-
return children['\0'] != nullptr;
123+
return is_leaf;
118124
}
119125
};
120126

Collapse file

‎test/parallel/test-permission-fs-wildcard.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-permission-fs-wildcard.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ if (common.isWindows) {
5959
'/slower',
6060
'/slown',
6161
'/home/foo/*',
62+
'/files/index.js',
63+
'/files/index.json',
64+
'/files/i',
6265
];
6366
const { status, stderr } = spawnSync(
6467
process.execPath,
@@ -74,6 +77,10 @@ if (common.isWindows) {
7477
assert.ok(process.permission.has('fs.read', '/home/foo'));
7578
assert.ok(process.permission.has('fs.read', '/home/foo/'));
7679
assert.ok(!process.permission.has('fs.read', '/home/fo'));
80+
assert.ok(process.permission.has('fs.read', '/files/index.js'));
81+
assert.ok(process.permission.has('fs.read', '/files/index.json'));
82+
assert.ok(!process.permission.has('fs.read', '/files/index.j'));
83+
assert.ok(process.permission.has('fs.read', '/files/i'));
7784
`,
7885
]
7986
);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.