GeezerVison is showing github.com — permission: handle end nodes with children cases · nodejs/node@4efa680
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/permission/fs_permission.cc -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -132,7 +132,6 @@ bool FSPermission::RadixTree::Lookup(const std::string_view& s, | 132 | 132 | if (current_node->children.size() == 0) { | 133 | 133 | return when_empty_return; | 134 | 134 | } | 135 | | - | 136 | 135 | unsigned int parent_node_prefix_len = current_node->prefix.length(); | 137 | 136 | const std::string path(s); | 138 | 137 | auto path_len = path.length(); | |
Collapse file Copy file name to clipboardExpand all lines: src/permission/fs_permission.h +9-3Lines changed: 9 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,13 +25,18 @@ class FSPermission final : public PermissionBase { | 25 | 25 | std::string prefix; | 26 | 26 | std::unordered_map<char, Node*> children; | 27 | 27 | Node* wildcard_child; | | 28 | + bool is_leaf; | 28 | 29 |
| 29 | 30 | explicit Node(const std::string& pre) | 30 | | - : prefix(pre), wildcard_child(nullptr) {} | | 31 | + : prefix(pre), wildcard_child(nullptr), is_leaf(false) {} | 31 | 32 |
| 32 | | - Node() : wildcard_child(nullptr) {} | | 33 | + Node() : wildcard_child(nullptr), is_leaf(false) {} | 33 | 34 |
| 34 | 35 | Node* CreateChild(std::string prefix) { | | 36 | + if (prefix.empty() && !is_leaf) { | | 37 | + is_leaf = true; | | 38 | + return this; | | 39 | + } | 35 | 40 | char label = prefix[0]; | 36 | 41 |
| 37 | 42 | Node* child = children[label]; | @@ -56,6 +61,7 @@ class FSPermission final : public PermissionBase { | 56 | 61 | return split_child->CreateChild(prefix.substr(i)); | 57 | 62 | } | 58 | 63 | } | | 64 | + child->is_leaf = true; | 59 | 65 | return child->CreateChild(prefix.substr(i)); | 60 | 66 | } | 61 | 67 |
| @@ -114,7 +120,7 @@ class FSPermission final : public PermissionBase { | 114 | 120 | if (children.size() == 0) { | 115 | 121 | return true; | 116 | 122 | } | 117 | | - return children['\0'] != nullptr; | | 123 | + return is_leaf; | 118 | 124 | } | 119 | 125 | }; | 120 | 126 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-permission-fs-wildcard.js +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,6 +59,9 @@ if (common.isWindows) { | 59 | 59 | '/slower', | 60 | 60 | '/slown', | 61 | 61 | '/home/foo/*', | | 62 | + '/files/index.js', | | 63 | + '/files/index.json', | | 64 | + '/files/i', | 62 | 65 | ]; | 63 | 66 | const { status, stderr } = spawnSync( | 64 | 67 | process.execPath, | @@ -74,6 +77,10 @@ if (common.isWindows) { | 74 | 77 | assert.ok(process.permission.has('fs.read', '/home/foo')); | 75 | 78 | assert.ok(process.permission.has('fs.read', '/home/foo/')); | 76 | 79 | 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')); | 77 | 84 | `, | 78 | 85 | ] | 79 | 86 | ); | |
|