Skip to content

Commit d36b987

Browse files
committed
A space character is no longer accepted as a valid short option
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@955277 13f79535-47bb-0310-9956-ffa450edef68
1 parent d8df510 commit d36b987

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/main/java/org/apache/commons/cli/OptionValidator.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ static void validateOption(String opt) throws IllegalArgumentException
4949
{
5050
return;
5151
}
52-
52+
5353
// handle the single character opt
54-
else if (opt.length() == 1)
54+
if (opt.length() == 1)
5555
{
5656
char ch = opt.charAt(0);
5757

5858
if (!isValidOpt(ch))
5959
{
60-
throw new IllegalArgumentException("illegal option value '" + ch + "'");
60+
throw new IllegalArgumentException("Illegal option name '" + ch + "'");
6161
}
6262
}
6363

@@ -70,7 +70,7 @@ else if (opt.length() == 1)
7070
{
7171
if (!isValidChar(chars[i]))
7272
{
73-
throw new IllegalArgumentException("opt contains illegal character value '" + chars[i] + "'");
73+
throw new IllegalArgumentException("The option '" + opt + "' contains an illegal character : '" + chars[i] + "'");
7474
}
7575
}
7676
}
@@ -80,12 +80,11 @@ else if (opt.length() == 1)
8080
* Returns whether the specified character is a valid Option.
8181
*
8282
* @param c the option to validate
83-
* @return true if <code>c</code> is a letter, ' ', '?' or '@',
84-
* otherwise false.
83+
* @return true if <code>c</code> is a letter, '?' or '@', otherwise false.
8584
*/
8685
private static boolean isValidOpt(char c)
8786
{
88-
return isValidChar(c) || c == ' ' || c == '?' || c == '@';
87+
return isValidChar(c) || c == '?' || c == '@';
8988
}
9089

9190
/**

src/test/java/org/apache/commons/cli/OptionBuilderTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public void testSpecialOptChars() throws Exception
9797
// '@'
9898
Option opt2 = OptionBuilder.withDescription("read from stdin").create('@');
9999
assertEquals("@", opt2.getOpt());
100+
101+
// ' '
102+
try {
103+
OptionBuilder.create(' ');
104+
fail( "IllegalArgumentException not caught" );
105+
} catch (IllegalArgumentException e) {
106+
// success
107+
}
100108
}
101109

102110
public void testOptionArgNumbers()

0 commit comments

Comments
 (0)