Skip to content

Commit

Permalink
fix:the commoa separated bug
Browse files Browse the repository at this point in the history
  • Loading branch information
liewstar committed Jul 25, 2024
1 parent 4ab6346 commit 23943c5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/org/casbin/jcasbin/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ 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 @@ -270,12 +274,21 @@ public static String[] splitCommaDelimited(String s) {
String[] records = null;
if (s != null) {
try {
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);
s = sb.toString();
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).trim();
records[i] = csvRecords.get(0).get(i).replace(MEDIAN, ",").trim();
}
} catch (IOException e) {
Util.logPrintfError("CSV parser failed to parse this line: " + s, e);
Expand Down

0 comments on commit 23943c5

Please sign in to comment.