Updated StringArgumentType.escapeIfRequired to new string rules
This commit is contained in:
parent
8bf57b4a9a
commit
87f65f2bd2
4 changed files with 7 additions and 5 deletions
|
@ -3,7 +3,7 @@ import groovy.io.FileType
|
|||
apply plugin: 'java-library'
|
||||
apply plugin: 'maven'
|
||||
|
||||
version = '0.1.9'
|
||||
version = '0.1.10'
|
||||
group = 'com.mojang'
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
|
|
|
@ -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("")));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue