Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/permission/fs_permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ bool FSPermission::RadixTree::Lookup(const std::string_view& s,
if (current_node->children.size() == 0) {
return when_empty_return;
}

unsigned int parent_node_prefix_len = current_node->prefix.length();
const std::string path(s);
auto path_len = path.length();
Expand Down
12 changes: 9 additions & 3 deletions src/permission/fs_permission.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ class FSPermission final : public PermissionBase {
std::string prefix;
std::unordered_map<char, Node*> children;
Node* wildcard_child;
bool is_leaf;

explicit Node(const std::string& pre)
: prefix(pre), wildcard_child(nullptr) {}
: prefix(pre), wildcard_child(nullptr), is_leaf(false) {}

Node() : wildcard_child(nullptr) {}
Node() : wildcard_child(nullptr), is_leaf(false) {}

Node* CreateChild(std::string prefix) {
if (prefix.empty() && !is_leaf) {
is_leaf = true;
return this;
}
char label = prefix[0];

Node* child = children[label];
Expand All @@ -56,6 +61,7 @@ class FSPermission final : public PermissionBase {
return split_child->CreateChild(prefix.substr(i));
}
}
child->is_leaf = true;
return child->CreateChild(prefix.substr(i));
}

Expand Down Expand Up @@ -114,7 +120,7 @@ class FSPermission final : public PermissionBase {
if (children.size() == 0) {
return true;
}
return children['\0'] != nullptr;
return is_leaf;
}
};

Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-permission-fs-wildcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ if (common.isWindows) {
'/slower',
'/slown',
'/home/foo/*',
'/files/index.js',
'/files/index.json',
'/files/i',
];
const { status, stderr } = spawnSync(
process.execPath,
Expand All @@ -74,6 +77,10 @@ if (common.isWindows) {
assert.ok(process.permission.has('fs.read', '/home/foo'));
assert.ok(process.permission.has('fs.read', '/home/foo/'));
assert.ok(!process.permission.has('fs.read', '/home/fo'));
assert.ok(process.permission.has('fs.read', '/files/index.js'));
assert.ok(process.permission.has('fs.read', '/files/index.json'));
assert.ok(!process.permission.has('fs.read', '/files/index.j'));
assert.ok(process.permission.has('fs.read', '/files/i'));
`,
]
);
Expand Down