Fix ArgumentString not properly supporting single quote

This commit is contained in:
themode 2021-03-13 05:05:08 +01:00
parent e333eb3749
commit 3975a0dffd

View File

@ -14,7 +14,9 @@ import org.jetbrains.annotations.NotNull;
*/
public class ArgumentString extends Argument<String> {
public static final char BACKSLASH = '\\';
private static final char BACKSLASH = '\\';
private static final char DOUBLE_QUOTE = '"';
private static final char QUOTE = '\'';
public static final int QUOTE_ERROR = 1;
@ -44,7 +46,8 @@ public class ArgumentString extends Argument<String> {
public static String staticParse(@NotNull String input) throws ArgumentSyntaxException {
// Return if not quoted
if (!input.contains(String.valueOf(StringUtil.DOUBLE_QUOTE)) &&
if (!input.contains(String.valueOf(DOUBLE_QUOTE)) &&
!input.contains(String.valueOf(QUOTE)) &&
!input.contains(String.valueOf(StringUtil.SPACE))) {
return input;
}
@ -53,7 +56,7 @@ public class ArgumentString extends Argument<String> {
final char first = input.charAt(0);
final char last = input.charAt(input.length() - 1);
final boolean quote = input.length() >= 2 &&
first == StringUtil.DOUBLE_QUOTE && last == StringUtil.DOUBLE_QUOTE;
first == last && (first == DOUBLE_QUOTE || first == QUOTE);
if (!quote)
throw new ArgumentSyntaxException("String argument needs to start and end with quotes", input, QUOTE_ERROR);
@ -63,7 +66,7 @@ public class ArgumentString extends Argument<String> {
// Verify backslashes
for (int i = 1; i < input.length(); i++) {
final char c = input.charAt(i);
if (c == StringUtil.DOUBLE_QUOTE) {
if (c == first) {
final char lastChar = input.charAt(i - 1);
if (lastChar != BACKSLASH) {
throw new ArgumentSyntaxException("Non-escaped quote", input, QUOTE_ERROR);