Can not escape comma in policy rule
See original GitHub issueHi, I am using ABAC via “jcasbin” and I am facing an issue related to the CSV Parsing of the policy. I am using the 1.20.0 version. My policy includes double quotes and CSV Parser is failing with the following error:
java.io.IOException: (line 1) invalid char between encapsulated token and delimiter
at org.apache.commons.csv.Lexer.parseEncapsulatedToken(Lexer.java:281)
at org.apache.commons.csv.Lexer.nextToken(Lexer.java:158)
at org.apache.commons.csv.CSVParser.nextRecord(CSVParser.java:674)
at org.apache.commons.csv.CSVParser.getRecords(CSVParser.java:628)
at org.casbin.jcasbin.util.Util.splitCommaDelimited(Util.java:236)
Here is the policy file:
p, user, /data1, read, {"Equals":{"seller_id":"123", "corp":"CompanyA"}}
Without comma in json, it could work fine
p, user, /data1, read, {"Equals":{"seller_id":"123"}}
I have tried several solutions but they still do not work. such as
p2, user, /data1, read, {""Equals"":{""seller_id"":""123"", ""corp"":""CompanyA""}}
p2, user, /data1, read, "{""Equals"":{""seller_id"":""123"", ""corp"":""CompanyA""}}"
I also checked the issues: https://github.com/casbin/jcasbin/issues/158 & https://github.com/casbin/jcasbin/issues/184 but the result is still the same.
Could you please help with this?
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Question: Is there a way to escape comma in policy rule? #158
In this way, you need to make sure that there is a space after the comma in the model file and the policy...
Read more >3 Must-Know Comma Rules for Lawyers - WordRake
Never use commas with restrictive modifiers · Always use commas with non-restrictive modifiers · Consistently use commas before the final item in a...
Read more >How should I escape commas and speech marks in CSV files ...
We eventually found the answer to this. Excel will only respect the escaping of commas and speech marks if the column value is...
Read more >Comma Rules for Clear Writing (with Examples) - HubSpot Blog
Use a comma to link an incomplete sentence with a complete sentence. An incomplete sentence doesn't express a fully formed thought and can't ......
Read more >5 Comma Rules You Can Sometimes Break | Liminal Pages
It's true that a comma does create a pause in a sentence, but reverse-engineering this idea doesn't help you use commas correctly. As...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@huyphan-tiki The exception is caused by this line when loading policy data from the adapter. It uses method splitCommaDelimited to split a comma-delimited string. I have a solution which makes CSVParser support the escape character
\
. Then you can save your policy data as below.If there is no question, I will open a PR. But I’m not sure whether this will cause other problems or not. @hsluoyz
@huyphan-tiki OK then.
@seriouszyx