Skip to content

Commit

Permalink
feat: Revert "feat: fix the double quotes caused eval() bug" (#448)
Browse files Browse the repository at this point in the history
This reverts commit 50d1967.
  • Loading branch information
hsluoyz authored Dec 25, 2024
1 parent 50d1967 commit bf39736
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 43 deletions.
7 changes: 0 additions & 7 deletions src/main/java/org/casbin/jcasbin/main/CoreEnforcer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
import java.util.function.BiPredicate;
import java.util.function.Function;

import static org.casbin.jcasbin.util.Util.hasEval;
import static org.casbin.jcasbin.util.Util.splitCommaDelimitedList;

/**
* CoreEnforcer defines the core functionality of an enforcer.
*/
Expand Down Expand Up @@ -583,7 +580,6 @@ private EnforceResult enforce(String matcher, Object... rvals) {
} else {
expString = Util.removeComments(Util.escapeAssertion(matcher));
}
boolean hasEval = hasEval(expString);

// json process
if (acceptJsonRequest) {
Expand Down Expand Up @@ -633,9 +629,6 @@ private EnforceResult enforce(String matcher, Object... rvals) {

for (int i = 0; i < policy.size(); i++) {
List<String> pvals = policy.get(i);
if (hasEval) {
pvals = splitCommaDelimitedList(pvals);
}
Map<String, Object> parameters = new HashMap<>(rvals.length + pTokens.length);
getPTokens(parameters, pType, pvals, pTokens);
getRTokens(parameters, rType, rvals);
Expand Down
17 changes: 1 addition & 16 deletions src/main/java/org/casbin/jcasbin/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,21 +284,6 @@ public static String[] splitCommaDelimited(String s) {
return records;
}

/**
* splits each string in the given list by commas according to CSV format
* and removes any extra double quotes
* @param rule the rule to be modified
* @return the modified rule
*/
public static List<String> splitCommaDelimitedList(List<String> rule) {
List<String> modifiedRule = new ArrayList<>();
for (String s : rule) {
String[] strings = splitCommaDelimited(s);
modifiedRule.add(strings[0]);
}
return modifiedRule;
}

/**
* setEquals determines whether two string sets are identical.
*
Expand Down Expand Up @@ -329,7 +314,7 @@ public static boolean setEquals(List<String> a, List<String> b) {
}

public static boolean hasEval(String exp) {
return evalReg.matcher(exp).find();
return evalReg.matcher(exp).matches();
}

public static String replaceEval(String s, String replacement) {
Expand Down
13 changes: 1 addition & 12 deletions src/test/java/org/casbin/jcasbin/main/AbacAPIUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@

package org.casbin.jcasbin.main;

import org.casbin.jcasbin.util.Util;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

Expand All @@ -44,15 +42,6 @@ public void testEval() {
alice.setAge(60);
testEnforce(e, alice, "/data2", "read", false);
testEnforce(e, alice, "/data2", "write", false);

List<String> rule = new ArrayList<>();
rule.add("\"r.sub.name == 'alice,green'\"");
rule.add("data1");
rule.add("read");
e.addPolicy(rule);

TestEvalRule aliceGreen = new TestEvalRule("alice,green", 18);
testEnforce(e, aliceGreen, "data1", "read", true);
}

@Test
Expand Down
8 changes: 0 additions & 8 deletions src/test/java/org/casbin/jcasbin/main/UtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.IOException;
import java.io.StringReader;

import static org.casbin.jcasbin.util.Util.hasEval;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;

Expand Down Expand Up @@ -85,13 +84,6 @@ public void testSplitCommaDelimited(){
assertArrayEquals(new String[]{"a b", "c", "d"}, Util.splitCommaDelimited("\"a b\", c, d"));
}

@Test
public void testHasEval() {
assertTrue(hasEval("eval(test)"));
assertTrue(hasEval("r_act == p_act && eval(p_sub_rule) && eval(p_obj_rule)"));
assertFalse(hasEval("evaltest"));
}

@Test
public void testReplaceEval() {
Util.logPrint(Util.replaceEval("eval(test)", "testEval"));
Expand Down

0 comments on commit bf39736

Please sign in to comment.