Skip to content

Commit e8e4efa

Browse files
committed
Merge branch 'kumarp149-CLI-313'
2 parents 3427839 + 0374dee commit e8e4efa

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/main/java/org/apache/commons/cli/DefaultParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ private boolean isArgument(final String token) {
580580
* Tests if the specified token is a Java-like property (-Dkey=value).
581581
*/
582582
private boolean isJavaProperty(final String token) {
583-
final String opt = token.substring(0, 1);
583+
final String opt = token.isEmpty() ? null : token.substring(0, 1);
584584
final Option option = options.getOption(opt);
585585

586586
return option != null && (option.getArgs() >= 2 || option.getArgs() == Option.UNLIMITED_VALUES);

src/test/java/org/apache/commons/cli/AbstractParserTestCase.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,5 +1021,12 @@ public void testWithRequiredOption() throws Exception {
10211021
assertEquals("Confirm arg of -b", "file", cl.getOptionValue("b"));
10221022
assertTrue("Confirm NO of extra args", cl.getArgList().isEmpty());
10231023
}
1024-
1024+
1025+
@Test(expected = UnrecognizedOptionException.class)
1026+
public void testAmbiguousArgParsing() throws Exception {
1027+
final String[] args = {"-=-"};
1028+
final Options options = new Options();
1029+
1030+
final CommandLine cl = parser.parse(options, args);
1031+
}
10251032
}

0 commit comments

Comments
 (0)