question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not escape comma in policy rule

See original GitHub issue

Hi, 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:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
seriouszyxcommented, Dec 4, 2021

@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.

p2, user, /data1, read, {"Equals":{"seller_id":"123"\, "corp":"CompanyA"}}

If there is no question, I will open a PR. But I’m not sure whether this will cause other problems or not. @hsluoyz

0reactions
hsluoyzcommented, Dec 5, 2021
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found