New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KAFKA-7388 equal sign in property value for password #5630
Changes from 5 commits
56c64cf
0272068
141b0df
566f47f
35a7f8c
c92091b
28ef6c9
87f1350
120872e
7b3c400
e39790f
4036b5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,19 +60,15 @@ 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)}") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. below else {} is not required as we always have length 2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the else block is not required There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed and added more test cases for more edge cases |
||
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 props.put(a(0), a(1)) | ||
} | ||
props | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,12 +29,19 @@ class CommandLineUtilsTest { | |
CommandLineUtils.parseKeyValueArgs(argArray, false) | ||
} | ||
|
||
@Test(expected = classOf[java.lang.IllegalArgumentException]) | ||
def testParseEmptyArgWithNoDelimiter() { | ||
val argArray = Array("my.empty.property") | ||
CommandLineUtils.parseKeyValueArgs(argArray, false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Perhaps name the boolean arg here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
|
||
@Test | ||
def testParseEmptyArgAsValid() { | ||
val argArray = Array("my.empty.property=") | ||
val argArray = Array("my.empty.property=", "my.empty.property1") | ||
val props = CommandLineUtils.parseKeyValueArgs(argArray) | ||
|
||
assertEquals("Value of a key with missing value should be an empty string",props.getProperty("my.empty.property"),"") | ||
assertEquals("Value of a key with missing value with no delimiter should be an empty string",props.getProperty("my.empty.property1"),"") | ||
} | ||
|
||
@Test | ||
|
@@ -52,4 +59,14 @@ class CommandLineUtilsTest { | |
assertEquals("Value of second property should be 'second'",props.getProperty("second.property"),"second") | ||
} | ||
|
||
@Test | ||
def testParseArgsWithMultipleDelimiters() { | ||
val argArray = Array("first.property==first","second.property=second=", "third.property=thi=rd") | ||
val props = CommandLineUtils.parseKeyValueArgs(argArray, false) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a space between method arguments at below lines There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed for the whole file |
||
assertEquals("Value of first property should be '=first'",props.getProperty("first.property"),"=first") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a space between method arguments here and other places There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added 👍 |
||
assertEquals("Value of second property should be 'second='",props.getProperty("second.property"),"second=") | ||
assertEquals("Value of second property should be 'thi=rd'",props.getProperty("third.property"),"thi=rd") | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can you add a comment to say that
value
may contain equals?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done