Updated StringArgumentType.escapeIfRequired to new string rules
This commit is contained in:
@@ -137,7 +137,7 @@ public class StringReader implements ImmutableStringReader {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isAllowedInUnquotedString(final char c) {
|
||||
public static boolean isAllowedInUnquotedString(final char c) {
|
||||
return c >= '0' && c <= '9'
|
||||
|| c >= 'A' && c <= 'Z'
|
||||
|| c >= 'a' && c <= 'z'
|
||||
|
||||
@@ -52,8 +52,10 @@ public class StringArgumentType implements ArgumentType<String> {
|
||||
}
|
||||
|
||||
public static String escapeIfRequired(final String input) {
|
||||
if (input.contains("\\") || input.contains("\"") || input.contains(CommandDispatcher.ARGUMENT_SEPARATOR)) {
|
||||
return escape(input);
|
||||
for (final char c : input.toCharArray()) {
|
||||
if (!StringReader.isAllowedInUnquotedString(c)) {
|
||||
return escape(input);
|
||||
}
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class StringArgumentTypeTest {
|
||||
|
||||
@Test
|
||||
public void testEscapeIfRequired_notRequired() throws Exception {
|
||||
assertThat(escapeIfRequired("hello!"), is(equalTo("hello!")));
|
||||
assertThat(escapeIfRequired("hello"), is(equalTo("hello")));
|
||||
assertThat(escapeIfRequired(""), is(equalTo("")));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user