Skip to content

Commit 98432aa

Browse files
authored
fix: update keyMatch2 for key2 == * (casbin#344)
1 parent d9564ef commit 98432aa

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/main/java/org/casbin/jcasbin/util/BuiltInFunctions.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ public static boolean keyMatch(String key1, String key2) {
7373
*/
7474
public static boolean keyMatch2(String key1, String key2) {
7575
key2 = key2.replace("/*", "/.*");
76-
key2 = "^" + KEY_MATCH2_PATTERN.matcher(key2).replaceAll("[^/]+") + "$";
77-
return regexMatch(key1, key2);
76+
key2 = KEY_MATCH2_PATTERN.matcher(key2).replaceAll("[^/]+");
77+
if(Objects.equals(key2, "*")) {
78+
key2 = "(.*)";
79+
}
80+
return regexMatch(key1, "^" + key2 + "$");
7881
}
7982

8083
/**

src/test/java/org/casbin/jcasbin/main/BuiltInFunctionsUnitTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public void testKeyMatch2Func() {
6868
testKeyMatch2("/alice/all", "/:id", false);
6969

7070
testKeyMatch2("/alice/all", "/:/all", false);
71+
72+
testKeyMatch2("engines/engine1", "*", true);
7173
}
7274

7375
@Test

0 commit comments

Comments
 (0)