You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Emmanuel Bourg (JIRA)" <ji...@apache.org> on 2010/06/16 01:56:22 UTC

[jira] Created: (CLI-201) Default options may be partially processed

Default options may be partially processed
------------------------------------------

                 Key: CLI-201
                 URL: https://issues.apache.org/jira/browse/CLI-201
             Project: Commons CLI
          Issue Type: Bug
          Components: Parser
    Affects Versions: 1.1
            Reporter: Emmanuel Bourg
            Priority: Minor
             Fix For: 1.3


The Properties instance passed to the Parser.parse() method to initialize the default options may be partially processed. This happens when the properties contains an option that doesn't accept arguments and has a default value that isn't evaluated to "true". When this case occurs the processing of the properties is stopped and the remaining options are never handled.

This is caused by the break statement in Parser.processProperties(Properties), a continue statement should have been used instead.

The related test in ValueTest is also wrong, there are two assertions that need to be changed:

{code}
Options opts = new Options();
opts.addOption("a", false, "toggle -a");
opts.addOption("c", "c", false, "toggle -c");
opts.addOption(OptionBuilder.hasOptionalArg().create('e'));

properties = new Properties();
properties.setProperty( "a", "false" );
properties.setProperty( "c", "no" );
properties.setProperty( "e", "0" );

cmd = parser.parse(opts, null, properties);
assertTrue( !cmd.hasOption("a") );
assertTrue( !cmd.hasOption("c") );
assertTrue( !cmd.hasOption("e") ); // Wrong, this option accepts an argument and should receive the value "0"
{code}

 and the second one:

{code}
properties = new Properties();
properties.setProperty( "a", "just a string" );
properties.setProperty( "e", "" );

cmd = parser.parse(opts, null, properties);
assertTrue( !cmd.hasOption("a") );
assertTrue( !cmd.hasOption("c") );
assertTrue( !cmd.hasOption("e") ); // Wrong, this option accepts an argument and should receive an empty string as value
{code}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (CLI-201) Default options may be partially processed

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-201?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bourg resolved CLI-201.
--------------------------------

    Resolution: Fixed

> Default options may be partially processed
> ------------------------------------------
>
>                 Key: CLI-201
>                 URL: https://issues.apache.org/jira/browse/CLI-201
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.1
>            Reporter: Emmanuel Bourg
>            Priority: Minor
>             Fix For: 1.3
>
>
> The Properties instance passed to the Parser.parse() method to initialize the default options may be partially processed. This happens when the properties contains an option that doesn't accept arguments and has a default value that isn't evaluated to "true". When this case occurs the processing of the properties is stopped and the remaining options are never handled.
> This is caused by the break statement in Parser.processProperties(Properties), a continue statement should have been used instead.
> The related test in ValueTest is also wrong, there are two assertions that need to be changed:
> {code}
> Options opts = new Options();
> opts.addOption("a", false, "toggle -a");
> opts.addOption("c", "c", false, "toggle -c");
> opts.addOption(OptionBuilder.hasOptionalArg().create('e'));
> properties = new Properties();
> properties.setProperty( "a", "false" );
> properties.setProperty( "c", "no" );
> properties.setProperty( "e", "0" );
> cmd = parser.parse(opts, null, properties);
> assertTrue( !cmd.hasOption("a") );
> assertTrue( !cmd.hasOption("c") );
> assertTrue( !cmd.hasOption("e") ); // Wrong, this option accepts an argument and should receive the value "0"
> {code}
>  and the second one:
> {code}
> properties = new Properties();
> properties.setProperty( "a", "just a string" );
> properties.setProperty( "e", "" );
> cmd = parser.parse(opts, null, properties);
> assertTrue( !cmd.hasOption("a") );
> assertTrue( !cmd.hasOption("c") );
> assertTrue( !cmd.hasOption("e") ); // Wrong, this option accepts an argument and should receive an empty string as value
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.