Uploaded image for project: 'Commons CLI'
  1. Commons CLI
  2. CLI-225

Special properties option (-Dproperty=value) handled improperly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Problem
    • 1.2
    • None
    • CLI-1.x
    • None

    Description

      In CLI 1.2 the special properties option (-Dproperty=value) is handled improperly. In GnuParser.java from line 80 is as follows:

                          if (opt.indexOf('=') != -1 && options.hasOption(opt.substring(0, opt.indexOf('='))))
                          {
                              // the format is --foo=value or -foo=value
                              tokens.add(arg.substring(0, arg.indexOf('='))); // --foo
                              tokens.add(arg.substring(arg.indexOf('=') + 1)); // value
                          }
                          else if (options.hasOption(arg.substring(0, 2)))
                          {
                              // the format is a special properties option (-Dproperty=value)
                              tokens.add(arg.substring(0, 2)); // -D
                              tokens.add(arg.substring(2)); // property=value
                          }
      

      , but should be:

                          if (opt.indexOf('=') != -1)
                      	{
                      	    if (options.hasOption(opt.substring(0, opt.indexOf('='))))
      	                    {
      	                        // the format is --foo=value or -foo=value
      	                        tokens.add(arg.substring(0, arg.indexOf('='))); // --foo
      	                        tokens.add(arg.substring(arg.indexOf('=') + 1)); // value
      	                    }
      	                    else if (options.hasOption(arg.substring(0, 2)))
      	                    {
      	                        // the format is a special properties option (-Dproperty=value)
      	                        tokens.add(arg.substring(0, 2)); // -D
      	                        tokens.add(arg.substring(2)); // property=value
      	                    }
                      	}
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            alexis.tsvetkov@gmail.com Alexey Tsvetkov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: