Skip to content

Commit

Permalink
Treat any trailing space as "a yet to be finished command" instead of…
Browse files Browse the repository at this point in the history
… a maybe valid argument
  • Loading branch information
Dinnerbone committed Nov 8, 2017
1 parent 6e61fef commit 4d91bc6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import groovy.io.FileType
apply plugin: 'java-library'
apply plugin: 'maven'

version = '0.1.2'
version = '0.1.3'
group = 'com.mojang'

task wrapper(type: Wrapper) {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/mojang/brigadier/CommandDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,8 @@ private ParseResults<S> parseNodes(final CommandNode<S> node, final StringReader
}

context.withCommand(child.getCommand());
if (reader.canRead()) {
if (reader.canRead(2)) {
reader.skip();
}
if (reader.canRead(2)) {
reader.skip();
if (child.getRedirect() != null) {
final CommandContextBuilder<S> childContext = new CommandContextBuilder<>(this, source, reader.getCursor());
childContext.withNode(child.getRedirect(), new StringRange(reader.getCursor(), reader.getCursor()));
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/com/mojang/brigadier/CommandDispatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,24 @@ public void testExecuteSubcommand() throws Exception {

@SuppressWarnings("unchecked")
@Test
public void testParseIncomplete() throws Exception {
public void testParseIncompleteLiteral() throws Exception {
subject.register(literal("foo").then(literal("bar").executes(command)));

final ParseResults<Object> parse = subject.parse("foo ", source);
assertThat(parse.getReader().getRemaining(), equalTo(" "));
assertThat(parse.getContext().getNodes().size(), is(1));
}

@SuppressWarnings("unchecked")
@Test
public void testParseIncompleteArgument() throws Exception {
subject.register(literal("foo").then(argument("bar", integer()).executes(command)));

final ParseResults<Object> parse = subject.parse("foo ", source);
assertThat(parse.getReader().getRemaining(), equalTo(" "));
assertThat(parse.getContext().getNodes().size(), is(1));
}

@SuppressWarnings("unchecked")
@Test
public void testExecuteAmbiguiousParentSubcommand() throws Exception {
Expand Down

0 comments on commit 4d91bc6

Please sign in to comment.