Skip to content

Commit

Permalink
fix: 'in' operator causes the expression to lose content (#253)
Browse files Browse the repository at this point in the history
Signed-off-by: Yixiang Zhao <[email protected]>
  • Loading branch information
seriouszyx authored Jan 26, 2022
1 parent 84767f0 commit 629f545
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/java/org/casbin/jcasbin/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ public static String convertInSyntax(String expString) {
String reg = "([a-zA-Z0-9_.()\"]*) +in +([a-zA-Z0-9_.()\"]*)";
Matcher m1 = Pattern.compile(reg).matcher(expString);
StringBuffer sb = new StringBuffer();
boolean flag=false;
boolean flag = false;
while (m1.find()) {
flag=true;
m1.appendReplacement(sb,"include($2, $1)");
flag = true;
m1.appendReplacement(sb, "include($2, $1)");
}
return flag?sb.toString():expString;
m1.appendTail(sb);
return flag ? sb.toString() : expString;
}
/**
* removeComments removes the comments starting with # in the text.
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/casbin/jcasbin/main/UtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void testConvertInSyntax(){
assertEquals("include(r_obj, r_sub)", Util.convertInSyntax("r_sub in r_obj"));
assertEquals("include(r_obj, r_sub.name)", Util.convertInSyntax("r_sub.name in r_obj"));
assertEquals("include(r_obj.name, r_sub.name)", Util.convertInSyntax("r_sub.name in r_obj.name"));
assertEquals("include(r_obj, r_sub) && r.obj == p.obj", Util.convertInSyntax("r_sub in r_obj && r.obj == p.obj"));
}

@Test
Expand Down

0 comments on commit 629f545

Please sign in to comment.