Updated StringArgumentType.escapeIfRequired to new string rules

This commit is contained in:
Nathan Adams
2017-11-14 15:20:06 +01:00
parent 8bf57b4a9a
commit 87f65f2bd2
4 changed files with 7 additions and 5 deletions
@@ -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;
}