[ https://issues.apache.org/jira/browse/CLI-300?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Balz Guenat updated CLI-300: ---------------------------- 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"));}} was: 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"));}} > 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 > Priority: Major > > 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)