Closed m-ignatov closed 1 month ago
@tangyang9464 @imp2002
@m-ignatov can you make a PR?
Hi @hsluoyz,
I think the above mentioned PR covers the minimum that fixes the comma handling, tested it locally and works good.
If this proposal is okay for you, I guess quoteRule()
can be moved to the org.casbin.jcasbin.util.Util
class as well for code consistency.
Regards, Momchil
Hi,
I am using JCasbin 1.55.0 and JDBC Adapter 2.7.0 with the standard RBAC model:
Our policies contain data which might include commas (,).
As far as I understand from the docs, I need to enclose the data with double quotes to escape it. However, it took me much trial and error to set this everywhere - previously I had parsing issues, coming mainly from
Util.splitCommaDelimited()
method.I observed the issue when the policy is saved with quotes to the in-memory casbin model and to the DB. However, if the application is restarted and casbin reads again the policies from the DB, the quotes get stripped away. This caused issues when deleting policies for example due to string mismatch (comparing same strings, but one with quotes, other without).
What I have done so far is to extend the
org.casbin.adapter.JDBCAdapter
class and override the following methods by quoting therule
list strings before persisting to the DB:addPolicy() / removePolicy()
addPolicies() / removePolicies() / removeFilteredPolicy()
updatePolicy()
For now it seems to work. So my question/proposal would be if this comma/special symbol handling could be extended to the JDBC adapter or to JCasbin. It would be great if JCasbin could automatically handle the commas, so that consumers don't have to implement custom logic like this.
Looking forward to your thoughts on this.
Thanks and regards, Momchil