Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-310 Relax input restrictions on quoted strings #314

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ String test(@Arg String before, @Arg("message") @Quoted String message, @Arg("af
return before + "-" + message + "-" + after;
}

@Execute(name = "end-quoted")
String test2(@Arg String before, @Arg("message") @Quoted String message) {
return before + "-" + message;
}

}

@Test
Expand All @@ -24,6 +29,14 @@ void testSingle() {
.assertSuccess("before-test-after");
}

@Test
void testNoQuoted() {
platform.execute("test before test after")
.assertSuccess("before-test-after");
platform.execute("test end-quoted before \"test after end")
.assertSuccess("before-test after end");
}

@Test
void testMultiple() {
platform.execute("test before \"siema co tam\" after")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import dev.rollczi.litecommands.argument.resolver.standard.InstantArgumentResolver;
import dev.rollczi.litecommands.invalidusage.InvalidUsage;
import dev.rollczi.litecommands.permission.MissingPermissions;
import dev.rollczi.litecommands.quoted.QuotedError;

public class LiteMessages {

Expand Down Expand Up @@ -45,16 +44,6 @@ public class LiteMessages {
input -> "Invalid date format '" + input + "'! Use: <yyyy-MM-dd> <HH:mm:ss> (INSTANT_INVALID_FORMAT)"
);

/**
* Invalid quoted string format.
* e.g. when user doesn't provide start or end quote.
* @see dev.rollczi.litecommands.quoted.QuotedStringArgumentResolver
*/
public static final MessageKey<QuotedError> QUOTED_STRING_INVALID_FORMAT = MessageKey.of(
"quoted-string-invalid-format",
error -> "Invalid quoted string format '" + error.getContent() + "'! Use: \"hello world\" (QUOTED_STRING_INVALID_FORMAT)"
);

protected LiteMessages() {
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import dev.rollczi.litecommands.argument.suggester.SuggesterRegistry;
import dev.rollczi.litecommands.input.raw.RawInput;
import dev.rollczi.litecommands.invocation.Invocation;
import dev.rollczi.litecommands.message.LiteMessages;
import dev.rollczi.litecommands.message.MessageRegistry;
import dev.rollczi.litecommands.range.Range;
import dev.rollczi.litecommands.suggestion.Suggestion;
Expand Down Expand Up @@ -45,8 +44,7 @@ public ParseResult<String> parse(Invocation<SENDER> invocation, Argument<String>
String first = rawInput.next();

if (!first.startsWith(quote)) {
QuotedError error = new QuotedError(first, QuotedError.Cause.FIRST_QUOTE);
return ParseResult.failure(this.messageRegistry.getInvoked(LiteMessages.QUOTED_STRING_INVALID_FORMAT, invocation, error));
return ParseResult.success(first);
}

if (first.length() > 1 && first.endsWith(quote)) {
Expand All @@ -69,8 +67,7 @@ public ParseResult<String> parse(Invocation<SENDER> invocation, Argument<String>
return ParseResult.success(builder.toString());
}

QuotedError error = new QuotedError(builder.toString(), QuotedError.Cause.LAST_QUOTE);
return ParseResult.failure(this.messageRegistry.getInvoked(LiteMessages.QUOTED_STRING_INVALID_FORMAT, invocation, error));
return ParseResult.success(builder.toString());
}

@Override
Expand Down