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

[cli] Parameter value "-something" misinterpreted as a parameter

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: Nightly Builds
    • Fix Version/s: 1.1
    • Component/s: CLI-1.x
    • Labels:
      None
    • Environment:

      Operating System: Windows NT
      Platform: PC

    • Bugzilla Id:
      34831

      Description

      If a parameter value is passed that contains a hyphen as the (delimited) first
      character, CLI parses this a parameter. For example using the call
      java myclass -t "-something"
      Results in the parser creating the invalid parameter -o (noting that it is
      skipping the 's')

      My code is using the Posix parser as follows
      Options options = buildCommandLineOptions();
      CommandLineParser parser = new PosixParser();
      CommandLine commandLine = null;
      try {

      commandLine = parser.parse(options, args);
      }
      catch (ParseException e) {

      System.out.println("Invalid parameters. " + e.getMessage() + NEW_LINE);
      System.exit(EXIT_CODE_ERROR);
      }

      This has been tested against the nightly build dated 20050503.

      1. CL51.patch
        6 kB
        Brian Egge
      2. CL51.patch
        2 kB
        Brian Egge

        Activity

        Hide
        bayard Henri Yandell added a comment -

        The usual strategy here is to allow – as a way to indicate that the rest of the
        line is pure text. If it's not available, this should be added.

        Show
        bayard Henri Yandell added a comment - The usual strategy here is to allow – as a way to indicate that the rest of the line is pure text. If it's not available, this should be added.
        Hide
        brianegge Brian Egge added a comment -

        Fix so parser doesn't burst options which are not defined. (-s) in the above case.

        Includes unit test.

        Show
        brianegge Brian Egge added a comment - Fix so parser doesn't burst options which are not defined. (-s) in the above case. Includes unit test.
        Hide
        bayard Henri Yandell added a comment -

        Thanks for the patch Brian; could you repeat it without the automatic IDE refactoring? It makes it a lot harder to read the patch; and more importantly for people to look back at the changes and see what the actual change was.

        Changing from protected to private for burstToken is also often a tricky one to do as we're stuck in the wonderful world of maintaining backwards compatibility.

        The unit test looks good, but it'll need an Apache license and not an LGPL license (copy the header from the BugCLI18Test class).

        Show
        bayard Henri Yandell added a comment - Thanks for the patch Brian; could you repeat it without the automatic IDE refactoring? It makes it a lot harder to read the patch; and more importantly for people to look back at the changes and see what the actual change was. Changing from protected to private for burstToken is also often a tricky one to do as we're stuck in the wonderful world of maintaining backwards compatibility. The unit test looks good, but it'll need an Apache license and not an LGPL license (copy the header from the BugCLI18Test class).
        Hide
        brianegge Brian Egge added a comment -

        Updated patch. Removed incorrect license header; removed formatting changed; reverted access level change.

        Show
        brianegge Brian Egge added a comment - Updated patch. Removed incorrect license header; removed formatting changed; reverted access level change.
        Hide
        brianegge Brian Egge added a comment -

        Has anyone had the chance to try out the updated patch for this issue?

        Show
        brianegge Brian Egge added a comment - Has anyone had the chance to try out the updated patch for this issue?
        Hide
        bayard Henri Yandell added a comment -

        Patch format looks great - I'll aim to apply it later today.

        Show
        bayard Henri Yandell added a comment - Patch format looks great - I'll aim to apply it later today.
        Hide
        bayard Henri Yandell added a comment -

        svn ci -m "Applying test and fix patch from CLI-51. Thanks to Brian Egge. " src/
        Sending src/java/org/apache/commons/cli/PosixParser.java
        Adding src/test/org/apache/commons/cli/bug/BugCLI51Test.java
        Transmitting file data ..
        Committed revision 540661.

        Show
        bayard Henri Yandell added a comment - svn ci -m "Applying test and fix patch from CLI-51 . Thanks to Brian Egge. " src/ Sending src/java/org/apache/commons/cli/PosixParser.java Adding src/test/org/apache/commons/cli/bug/BugCLI51Test.java Transmitting file data .. Committed revision 540661.

          People

          • Assignee:
            bayard Henri Yandell
            Reporter:
            nigel_king@mlc.com.au Nigel King
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development