You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/05/16 16:44:00 UTC

[jira] [Commented] (KAFKA-5572) ConfigDef.Type.List should support escaping comma character

    [ https://issues.apache.org/jira/browse/KAFKA-5572?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16477704#comment-16477704 ] 

ASF GitHub Bot commented on KAFKA-5572:
---------------------------------------

jcustenborder closed pull request #3508: KAFKA-5572 - ConfigDef should be able to escape comma(s)
URL: https://github.com/apache/kafka/pull/3508
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java b/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java
index 28fc801a1e8..f04151bfc25 100644
--- a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java
+++ b/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java
@@ -695,8 +695,12 @@ else if (value instanceof String)
                     else if (value instanceof String)
                         if (trimmed.isEmpty())
                             return Collections.emptyList();
-                        else
-                            return Arrays.asList(trimmed.split("\\s*,\\s*", -1));
+                        else {
+                            final String[] parts = trimmed.split("\\s*(?<!\\\\),\\s*", -1);
+                            for (int i = 0; i < parts.length; i++)
+                                parts[i] = parts[i].replace("\\,", ",");
+                            return Arrays.asList(parts);
+                        }
                     else
                         throw new ConfigException(name, value, "Expected a comma separated list.");
                 case CLASS:
diff --git a/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java b/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java
index ed4997dea4b..e0f233476e4 100644
--- a/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java
+++ b/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java
@@ -29,6 +29,8 @@
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -39,6 +41,7 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 public class ConfigDefTest {
@@ -386,6 +389,27 @@ public void testMissingDependentConfigs() {
         configDef.parse(Collections.emptyMap());
     }
 
+    void assertList(List<String> expected, Object actual) {
+        assertTrue("actual should be a List", actual instanceof List);
+        final List<String> actualList = (List<String>) actual;
+        final Set<String> expectedSet = new LinkedHashSet<>(expected);
+        final Set<String> actualSet = new LinkedHashSet<>(actualList);
+        assertEquals("Lists do not match.", expectedSet, actualSet);
+    }
+
+    @Test
+    public void testEscapedComma() {
+        final ConfigDef configdef = new ConfigDef()
+            .define("test", Type.LIST, Importance.HIGH, "test");
+        final Map<String, String> settings = new LinkedHashMap<>();
+        settings.put("test", "one,two,three");
+
+        assertList(Arrays.asList("one", "two", "three"), configdef.parse(settings).get("test"));
+
+        settings.put("test", "'first' , 'second\\,escaped',normal,value");
+        assertList(Arrays.asList("'first'", "'second,escaped'", "normal", "value"), configdef.parse(settings).get("test"));
+    }
+
     @Test
     public void testBaseConfigDefDependents() {
         // Creating a ConfigDef based on another should compute the correct number of configs with no parent, even


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> ConfigDef.Type.List should support escaping comma character
> -----------------------------------------------------------
>
>                 Key: KAFKA-5572
>                 URL: https://issues.apache.org/jira/browse/KAFKA-5572
>             Project: Kafka
>          Issue Type: Improvement
>            Reporter: Jeremy Custenborder
>            Assignee: Jeremy Custenborder
>            Priority: Minor
>
> You should be able to include a comma in a list. Currently the split regex is only looks for comma. This should be escapable with as something like \,.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)