From 4d91bc6e7ec707733cf820adc2a28c9edebbf4d0 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Wed, 8 Nov 2017 09:35:27 +0100 Subject: [PATCH] Treat any trailing space as "a yet to be finished command" instead of a maybe valid argument --- build.gradle | 2 +- .../java/com/mojang/brigadier/CommandDispatcher.java | 6 ++---- .../com/mojang/brigadier/CommandDispatcherTest.java | 12 +++++++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 0b2d68be..1a372e0d 100644 --- a/build.gradle +++ b/build.gradle @@ -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) { diff --git a/src/main/java/com/mojang/brigadier/CommandDispatcher.java b/src/main/java/com/mojang/brigadier/CommandDispatcher.java index 25193be4..2d2f7ad6 100644 --- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java +++ b/src/main/java/com/mojang/brigadier/CommandDispatcher.java @@ -152,10 +152,8 @@ private ParseResults parseNodes(final CommandNode 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 childContext = new CommandContextBuilder<>(this, source, reader.getCursor()); childContext.withNode(child.getRedirect(), new StringRange(reader.getCursor(), reader.getCursor())); diff --git a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java index 3352b479..1d327909 100644 --- a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java +++ b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java @@ -175,7 +175,7 @@ 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 parse = subject.parse("foo ", source); @@ -183,6 +183,16 @@ public void testParseIncomplete() throws Exception { 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 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 {