Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.4
-
None
-
None
-
Windows 10, Java 11
Description
Assuming there is a short option with foo with one argument. Trying to parse a token like -foo=bar results in an UnrecognizedOptionException.
The same scenario works fine if the short option is only one char long.
The reason is an if-statement in DefaultParser.handleShortAndLongOption() (line 543 in v1.4), which checks opt.length() == 1 before checking if the option exists. IMO, this check should instead be isShortOption(opt).
The below code demonstrates the issue.
Options options = new Options();
Option option = Option.builder("foo").hasArg().build();
options.addOption(option);
String[] args = new String[] {"-foo=bar"};
DefaultParser parser = new DefaultParser();
CommandLine cmdLine = parser.parse(options, args);
assertEquals("bar", cmdLine.getOptionValue("foo"));