Skip to content

Commit

Permalink
feat: improve policy comma handling (#74)
Browse files Browse the repository at this point in the history
* Policy rule comma handling

* Policy rule comma handling

---------

Co-authored-by: Momchil Ignatov <momchil.ignatov@sap.com>
  • Loading branch information
m-ignatov and momchil-ignatov authored Aug 7, 2024
1 parent d3e66e8 commit 8e86da1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/org/casbin/adapter/JDBCBaseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ protected void migrate() throws SQLException {
}

protected void loadPolicyLine(CasbinRule line, Model model) {
escapeCasbinRule(line);
String lineText = line.ptype;
if (!"".equals(line.v0)) {
lineText += ", " + line.v0;
Expand Down Expand Up @@ -540,4 +541,20 @@ protected void retry(ExecutionContext<Void> ctx) throws SQLException {
protected String renderActualSql(String sql) {
return sql.replace(DEFAULT_TABLE_NAME, tableName);
}

private void escapeCasbinRule(CasbinRule line) {
line.v0 = escapeSingleRule(line.v0);
line.v1 = escapeSingleRule(line.v1);
line.v2 = escapeSingleRule(line.v2);
line.v3 = escapeSingleRule(line.v3);
line.v4 = escapeSingleRule(line.v4);
line.v5 = escapeSingleRule(line.v5);
}

private String escapeSingleRule(String rule) {
if (rule.isEmpty() || (rule.startsWith("\"") && rule.endsWith("\""))) {
return rule;
}
return String.format("\"%s\"", rule);
}
}

0 comments on commit 8e86da1

Please sign in to comment.