[ https://issues.apache.org/jira/browse/KAFKA-4754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16655373#comment-16655373 ]
ASF GitHub Bot commented on KAFKA-4754: --------------------------------------- omkreddy closed pull request #2529: KAFKA-4754: Correctly parse '=' characters in command line overrides URL: https://github.com/apache/kafka/pull/2529 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/core/src/main/scala/kafka/utils/CommandLineUtils.scala b/core/src/main/scala/kafka/utils/CommandLineUtils.scala index edf473e3a70..e0fc5c8f976 100644 --- a/core/src/main/scala/kafka/utils/CommandLineUtils.scala +++ b/core/src/main/scala/kafka/utils/CommandLineUtils.scala @@ -60,18 +60,16 @@ object CommandLineUtils extends Logging { * Parse key-value pairs in the form key=value */ def parseKeyValueArgs(args: Iterable[String], acceptMissingValue: Boolean = true): Properties = { - val splits = args.map(_ split "=").filterNot(_.length == 0) + val splits = args.map(_ split("=", 2)).filterNot(_.length == 0) val props = new Properties for (a <- splits) { - if (a.length == 1) { + if (a.length == 1 || (a.length == 2 && a(1).isEmpty)) { if (acceptMissingValue) props.put(a(0), "") else throw new IllegalArgumentException(s"Missing value for key ${a(0)}") - } - else if (a.length == 2) props.put(a(0), a(1)) - else { - System.err.println("Invalid command line properties: " + args.mkString(" ")) - Exit.exit(1) + } else { + // The length must be 2 based on the split limit above + props.put(a(0), a(1)) } } props diff --git a/core/src/test/scala/unit/kafka/KafkaConfigTest.scala b/core/src/test/scala/unit/kafka/KafkaConfigTest.scala index c934c4a1428..addf5ff8f96 100644 --- a/core/src/test/scala/unit/kafka/KafkaConfigTest.scala +++ b/core/src/test/scala/unit/kafka/KafkaConfigTest.scala @@ -55,12 +55,10 @@ class KafkaTest { val config4 = KafkaConfig.fromProps(Kafka.getPropsFromArgs(Array(propertiesFile, "--override", "log.cleanup.policy=compact,delete", "--override", "broker.id=2"))) assertEquals(2, config4.brokerId) assertEquals(util.Arrays.asList("compact","delete"), config4.logCleanupPolicy) - } - @Test(expected = classOf[FatalExitError]) - def testGetKafkaConfigFromArgsWrongSetValue(): Unit = { - val propertiesFile = prepareDefaultConfig() - KafkaConfig.fromProps(Kafka.getPropsFromArgs(Array(propertiesFile, "--override", "a=b=c"))) + // We should be able to handle arguments with a "=" character in the value + val config5 = KafkaConfig.fromProps(Kafka.getPropsFromArgs(Array(propertiesFile, "--override", "ssl.keystore.password=123=abc"))) + assertEquals("123=abc", config5.sslKeystorePassword.value) } @Test(expected = classOf[FatalExitError]) diff --git a/core/src/test/scala/unit/kafka/utils/CommandLineUtilsTest.scala b/core/src/test/scala/unit/kafka/utils/CommandLineUtilsTest.scala index 50023f80464..0c08da8cf69 100644 --- a/core/src/test/scala/unit/kafka/utils/CommandLineUtilsTest.scala +++ b/core/src/test/scala/unit/kafka/utils/CommandLineUtilsTest.scala @@ -44,6 +44,13 @@ class CommandLineUtilsTest { assertEquals("Value of a single property should be 'value' ",props.getProperty("my.property"),"value") } + @Test + def testParseWithEquals() { + val argArray = Array("my.property=abc=123") + val props = CommandLineUtils.parseKeyValueArgs(argArray) + assertEquals("Value of a single property should be 'abc=123'", props.getProperty("my.property"), "abc=123") + } + @Test def testParseArgs() { val argArray = Array("first.property=first","second.property=second") ---------------------------------------------------------------- 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: us...@infra.apache.org > Correctly parse '=' characters in command line overrides > -------------------------------------------------------- > > Key: KAFKA-4754 > URL: https://issues.apache.org/jira/browse/KAFKA-4754 > Project: Kafka > Issue Type: Bug > Affects Versions: 0.9.0.0 > Reporter: Grant Henke > Assignee: Grant Henke > Priority: Major > > When starting Kafka with an override parameter via "--override > my.parameter=myvalue". > If a value contains an '=' character it fails and exits with "Invalid command > line properties:.." > Often passwords contain an '=' character so its important to support that > value. -- This message was sent by Atlassian JIRA (v7.6.3#76005)