You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Balz Guenat (Jira)" <ji...@apache.org> on 2019/11/22 09:43:00 UTC
[jira] [Created] (CLI-300) DefaultParser fails to parse token
"-S=V" if short option is longer than 1 char
Balz Guenat created CLI-300:
-------------------------------
Summary: DefaultParser fails to parse token "-S=V" if short option is longer than 1 char
Key: CLI-300
URL: https://issues.apache.org/jira/browse/CLI-300
Project: Commons CLI
Issue Type: Bug
Components: Parser
Affects Versions: 1.4
Environment: Windows 10, Java 11
Reporter: Balz Guenat
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"));}}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)