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

View file

@ -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) {

View file

@ -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'

View file

@ -52,9 +52,11 @@ public class StringArgumentType implements ArgumentType<String> {
}
public static String escapeIfRequired(final String input) {
if (input.contains("\\") || input.contains("\"") || input.contains(CommandDispatcher.ARGUMENT_SEPARATOR)) {
for (final char c : input.toCharArray()) {
if (!StringReader.isAllowedInUnquotedString(c)) {
return escape(input);
}
}
return input;
}

View file

@ -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("")));
}