This is an automated email from the ASF dual-hosted git repository.
jinrongtong pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new 806454bc5e [ISSUE #7710] Handle blank string for UtilAll#split to fix
the bugs of ACL
806454bc5e is described below
commit 806454bc5e29d2f157cde99bdb082f94cdb377fa
Author: Qinglong-Lee <[email protected]>
AuthorDate: Tue Jan 2 19:07:45 2024 +0800
[ISSUE #7710] Handle blank string for UtilAll#split to fix the bugs of ACL
Co-authored-by: liqinglong <[email protected]>
---
common/src/main/java/org/apache/rocketmq/common/UtilAll.java | 5 +++++
common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java | 9 +++++++++
2 files changed, 14 insertions(+)
diff --git a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java
b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java
index 19efa9aa90..3629ae648b 100644
--- a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java
+++ b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java
@@ -43,6 +43,7 @@ import java.util.function.Supplier;
import java.util.zip.CRC32;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
+import java.util.Collections;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.validator.routines.InetAddressValidator;
import org.apache.rocketmq.common.constant.LoggerName;
@@ -681,6 +682,10 @@ public class UtilAll {
return null;
}
+ if (StringUtils.isBlank(str)) {
+ return Collections.EMPTY_LIST;
+ }
+
String[] addrArray = str.split(splitter);
return Arrays.asList(addrArray);
}
diff --git a/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
b/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
index 2d22d5254a..a2b498f077 100644
--- a/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
+++ b/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
@@ -142,6 +142,15 @@ public class UtilAllTest {
assertEquals("", UtilAll.join(objects, comma));
}
+ @Test
+ public void testSplit() {
+ List<String> list = Arrays.asList("groupA=DENY", "groupB=PUB|SUB",
"groupC=SUB");
+ String comma = ",";
+ assertEquals(list,
UtilAll.split("groupA=DENY,groupB=PUB|SUB,groupC=SUB", comma));
+ assertEquals(null, UtilAll.split(null, comma));
+ assertEquals(Collections.EMPTY_LIST, UtilAll.split("", comma));
+ }
+
static class DemoConfig {
private int demoWidth = 0;
private int demoLength = 0;