Skip to content

Commit

Permalink
Fixed commands with a trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone committed Nov 8, 2017
1 parent 2c39925 commit 6e61fef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 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.1'
version = '0.1.2'
group = 'com.mojang'

task wrapper(type: Wrapper) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/mojang/brigadier/CommandDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ private ParseResults<S> parseNodes(final CommandNode<S> node, final StringReader

context.withCommand(child.getCommand());
if (reader.canRead()) {
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
10 changes: 10 additions & 0 deletions src/test/java/com/mojang/brigadier/CommandDispatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ public void testExecuteSubcommand() throws Exception {
verify(subCommand).run(any(CommandContext.class));
}

@SuppressWarnings("unchecked")
@Test
public void testParseIncomplete() 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 testExecuteAmbiguiousParentSubcommand() throws Exception {
Expand Down

0 comments on commit 6e61fef

Please sign in to comment.