-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: split function accounting for quotes (#158)
* fix #157: split function accounting for quotes Added Util.splitCSVLine() function that splits a CSV-formatted string into an array of tokens, accounting for quotes (single and double) and escape characters. * fix CI warning Warning: "src/util/Util.lua:263:24: (W311) value assigned to variable sep is unused" * update split function - renamed from splitCSVLine to splitEnhanced, since it's not compliant to RFC 4180 and it could be deceiving; - added optional parameters; - now throws error if quotes are not closed; * update Util.splitEnhanced() - fixed its behaviour to comply with Casbin documentation (see the note at https://casbin.org/docs/policy-storage#loading-policy-from-a-csv-file and issue 886 at casbin/casbin): "If your file contains commas and double quotes, you should enclose the field in double quotes and double any embedded double quotes." Therefore I removed the extra behaviour related to single quotes ' and escape character \ and refactored the function. * added example with double quotes * Unit test for Util.splitEnhanced() * fixed basic with regex example * Update basic_policy_with_regex.csv typo * Unit test for regexMatch with {N,M} quantifier * more unit tests for Util.splitEnhanced - check if the last field is a quoted field - throwing error when there are extra characters after the double quote that closes the quoted field. * Update Util.lua - support for quotes in last field; - throws an exception if there are other characters after the double quote that closes the quoted field. * changed "sep" parameter name to "delim" (uniform to Util.split() ) * changed "line" parameter name to "str" (uniform to Util.split() )
- Loading branch information
Showing
6 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[request_definition] | ||
r = sub, obj, act | ||
|
||
[policy_definition] | ||
p = sub, obj, act | ||
|
||
[policy_effect] | ||
e = some(where (p.eft == allow)) | ||
|
||
[matchers] | ||
m = regexMatch(r.sub, p.sub) && regexMatch(r.obj, p.obj) && regexMatch(r.act, p.act) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p, ^admin$, .*, .* | ||
p, ^user.*, "^/users/[a-zA-Z0-9]{4,10}$", PUT|POST|PATCH|GET|OPTIONS | ||
p, ^guest$, ^/guest/.*, GET|OPTIONS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters