From 23943c5bba478d6eb7e678efb21507e4a44683a0 Mon Sep 17 00:00:00 2001 From: liewstar <2935437378@qq.com> Date: Thu, 25 Jul 2024 20:26:41 +0800 Subject: [PATCH] fix:the commoa separated bug --- src/main/java/org/casbin/jcasbin/util/Util.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/casbin/jcasbin/util/Util.java b/src/main/java/org/casbin/jcasbin/util/Util.java index d27923b5..8db791c5 100644 --- a/src/main/java/org/casbin/jcasbin/util/Util.java +++ b/src/main/java/org/casbin/jcasbin/util/Util.java @@ -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. * @@ -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 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);