-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #157: split function accounting for quotes #158
Conversation
Added Util.splitCSVLine() function that splits a CSV-formatted string into an array of tokens, accounting for quotes (single and double) and escape characters.
@Edmond-J-A @rushitote please review |
@mikyll fix CI errors: |
Warning: "src/util/Util.lua:263:24: (W311) value assigned to variable sep is unused"
- 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;
- 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.
- 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.
- support for quotes in last field; - throws an exception if there are other characters after the double quote that closes the quoted field.
(uniform to Util.split() )
(uniform to Util.split() )
SummaryDifferencesOld
|
🎉 This PR is included in version 1.41.9 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Allow to escape commas in policy rules. Especially useful for {N,M} pattern quantifier, which would otherwise throw an error (invalid policy size), since it considers the comma as a CSV field separator. Issue: casbin/lua-casbin#157 Fixed by: casbin/lua-casbin#158
Added Util.splitCSVLine() function that splits a CSV-formatted string into an array of tokens, accounting for quotes (single and double) and escape characters.