Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Revert "feat: fix the comma separater bug" #431

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions src/main/java/org/casbin/jcasbin/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@ public class Util {
public static boolean enableLog = true;
private static Pattern evalReg = Pattern.compile("\\beval\\(([^),]*)\\)");

private static Pattern BracketsReg = Pattern.compile("\\{[^}]*\\}");

private static Pattern escapeAssertionRegex = Pattern.compile("\\b(r|p)[0-9]*\\.");

private static Logger LOGGER = LoggerFactory.getLogger("org.casbin.jcasbin");

private static final String md5AlgorithmName = "MD5";

private static final String MEDIAN = "||";

/**
* logPrint prints the log.
*
Expand Down Expand Up @@ -274,13 +270,12 @@ public static String[] splitCommaDelimited(String s) {
String[] records = null;
if (s != null) {
try {
s = replaceCommaInBrackets(s);
CSVFormat csvFormat = CSVFormat.Builder.create().setIgnoreSurroundingSpaces(true).build();
CSVParser csvParser = csvFormat.parse(new StringReader(s));
List<CSVRecord> csvRecords = csvParser.getRecords();
records = new String[csvRecords.get(0).size()];
for (int i = 0; i < csvRecords.get(0).size(); i++) {
records[i] = csvRecords.get(0).get(i).replace(MEDIAN, ",").trim();
records[i] = csvRecords.get(0).get(i).trim();
}
} catch (IOException e) {
Util.logPrintfError("CSV parser failed to parse this line: " + s, e);
Expand Down Expand Up @@ -318,18 +313,6 @@ public static boolean setEquals(List<String> a, List<String> b) {
return true;
}

public static String replaceCommaInBrackets(String s){
Matcher matcher = BracketsReg.matcher(s);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
String match = matcher.group();
String replaced = match.replaceAll(",", MEDIAN);
matcher.appendReplacement(sb, replaced);
}
matcher.appendTail(sb);
return sb.length() > 0 ? sb.toString() : s;
}

public static boolean hasEval(String exp) {
return evalReg.matcher(exp).matches();
}
Expand Down
5 changes: 1 addition & 4 deletions src/test/java/org/casbin/jcasbin/main/UtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,9 @@ public void should_logged_when_splitCommaDelimited_given_ioException() {
MockedConstruction<CSVFormat> stringReaderMocked = BDDMockito.mockConstruction(CSVFormat.class, (mock, context) -> {
BDDMockito.given(mock.parse(any(StringReader.class))).willThrow(ioEx);
})) {

String csv = "\n";

// given
utilMocked.when(() -> Util.replaceCommaInBrackets(anyString())).thenReturn(csv);
utilMocked.when(() -> Util.splitCommaDelimited(anyString())).thenCallRealMethod();
String csv = "\n";

// when
Util.splitCommaDelimited(csv);
Expand Down
Loading