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
+1 -1
View File
@@ -3,7 +3,7 @@ import groovy.io.FileType
apply plugin: 'java-library' apply plugin: 'java-library'
apply plugin: 'maven' apply plugin: 'maven'
version = '0.1.9' version = '0.1.10'
group = 'com.mojang' group = 'com.mojang'
task wrapper(type: Wrapper) { 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' return c >= '0' && c <= '9'
|| c >= 'A' && c <= 'Z' || c >= 'A' && c <= 'Z'
|| 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) { public static String escapeIfRequired(final String input) {
if (input.contains("\\") || input.contains("\"") || input.contains(CommandDispatcher.ARGUMENT_SEPARATOR)) { for (final char c : input.toCharArray()) {
return escape(input); if (!StringReader.isAllowedInUnquotedString(c)) {
return escape(input);
}
} }
return input; return input;
} }
@@ -58,7 +58,7 @@ public class StringArgumentTypeTest {
@Test @Test
public void testEscapeIfRequired_notRequired() throws Exception { public void testEscapeIfRequired_notRequired() throws Exception {
assertThat(escapeIfRequired("hello!"), is(equalTo("hello!"))); assertThat(escapeIfRequired("hello"), is(equalTo("hello")));
assertThat(escapeIfRequired(""), is(equalTo(""))); assertThat(escapeIfRequired(""), is(equalTo("")));
} }