Skip to content

Commit 98fb14f

Browse files
committed
fix: add hyphens to regex pattern for permission matching
- Update regex pattern to include hyphens in permission names - Fix issue where hyphenated permissions like 'properties.view-all' were not being matched - All 161 tests now passing - User case 'properties.view-all||properties.view-own' now works correctly Fixes: Hyphenated permission names in logical expressions
1 parent 915132c commit 98fb14f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

hooks/use-permissions.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ export function usePermissions(permissions?: string[]) {
122122
// Breakdown of alternation groups:
123123
// \* - matches a standalone '*' wildcard
124124
// \? - matches a standalone '?' wildcard
125-
// [a-zA-Z_][a-zA-Z0-9_.*?]*(?:\.[a-zA-Z0-9_.*?]*)*
126-
// - matches standard permission strings, e.g. 'users.create', 'posts.*'
125+
// [a-zA-Z_][a-zA-Z0-9_.*?-]*(?:\.[a-zA-Z0-9_.*?-]*)*
126+
// - matches standard permission strings, e.g. 'users.create', 'posts.*', 'properties.view-all'
127127
// true|false - matches boolean literals 'true' or 'false'
128128
// The (?![|&]) negative lookahead ensures we don't match permission patterns that are immediately followed by a logical operator.
129129
const permissionRegex =
130-
/(?:\*|\?|[a-zA-Z_][a-zA-Z0-9_.*?]*(?:\.[a-zA-Z0-9_.*?]*)*|true|false)(?![|&])/g;
130+
/(?:\*|\?|[a-zA-Z_][a-zA-Z0-9_.*?-]*(?:\.[a-zA-Z0-9_.*?-]*)*|true|false)(?![|&])/g;
131131
const permissions = jsExpression.match(permissionRegex) || [];
132132

133133
// Replace each permission with its boolean evaluation

0 commit comments

Comments
 (0)