commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r955277 - in /commons/proper/cli/trunk/src: main/java/org/apache/commons/cli/OptionValidator.java test/java/org/apache/commons/cli/OptionBuilderTest.java
Date Wed, 16 Jun 2010 15:48:56 GMT
Author: ebourg
Date: Wed Jun 16 15:48:56 2010
New Revision: 955277

URL: http://svn.apache.org/viewvc?rev=955277&view=rev
Log:
A space character is no longer accepted as a valid short option

Modified:
    commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/OptionValidator.java
    commons/proper/cli/trunk/src/test/java/org/apache/commons/cli/OptionBuilderTest.java

Modified: commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/OptionValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/OptionValidator.java?rev=955277&r1=955276&r2=955277&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/OptionValidator.java (original)
+++ commons/proper/cli/trunk/src/main/java/org/apache/commons/cli/OptionValidator.java Wed
Jun 16 15:48:56 2010
@@ -49,15 +49,15 @@ class OptionValidator
         {
             return;
         }
-
+        
         // handle the single character opt
-        else if (opt.length() == 1)
+        if (opt.length() == 1)
         {
             char ch = opt.charAt(0);
 
             if (!isValidOpt(ch))
             {
-                throw new IllegalArgumentException("illegal option value '" + ch + "'");
+                throw new IllegalArgumentException("Illegal option name '" + ch + "'");
             }
         }
 
@@ -70,7 +70,7 @@ class OptionValidator
             {
                 if (!isValidChar(chars[i]))
                 {
-                    throw new IllegalArgumentException("opt contains illegal character value
'" + chars[i] + "'");
+                    throw new IllegalArgumentException("The option '" + opt + "' contains
an illegal character : '" + chars[i] + "'");
                 }
             }
         }
@@ -80,12 +80,11 @@ class OptionValidator
      * Returns whether the specified character is a valid Option.
      *
      * @param c the option to validate
-     * @return true if <code>c</code> is a letter, ' ', '?' or '@',
-     *         otherwise false.
+     * @return true if <code>c</code> is a letter, '?' or '@', otherwise false.
      */
     private static boolean isValidOpt(char c)
     {
-        return isValidChar(c) || c == ' ' || c == '?' || c == '@';
+        return isValidChar(c) || c == '?' || c == '@';
     }
 
     /**

Modified: commons/proper/cli/trunk/src/test/java/org/apache/commons/cli/OptionBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/java/org/apache/commons/cli/OptionBuilderTest.java?rev=955277&r1=955276&r2=955277&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/java/org/apache/commons/cli/OptionBuilderTest.java (original)
+++ commons/proper/cli/trunk/src/test/java/org/apache/commons/cli/OptionBuilderTest.java Wed
Jun 16 15:48:56 2010
@@ -97,6 +97,14 @@ public class OptionBuilderTest extends T
         // '@'
         Option opt2 = OptionBuilder.withDescription("read from stdin").create('@');
         assertEquals("@", opt2.getOpt());
+        
+        // ' '
+        try {
+            OptionBuilder.create(' ');
+            fail( "IllegalArgumentException not caught" );            
+        } catch (IllegalArgumentException e) {
+            // success
+        }
     }
 
     public void testOptionArgNumbers()



Mime
View raw message