Tags: casbin/lua-casbin
Tags
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() )
PreviousNext