diff --git a/src/main/java/com/mojang/brigadier/CommandDispatcher.java b/src/main/java/com/mojang/brigadier/CommandDispatcher.java index f27e5e1..e59a43a 100644 --- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java +++ b/src/main/java/com/mojang/brigadier/CommandDispatcher.java @@ -94,6 +94,11 @@ public class CommandDispatcher { final int cursor = reader.getCursor(); try { child.parse(reader, context); + if (reader.canRead()) { + if (reader.peek() != ARGUMENT_SEPARATOR_CHAR) { + throw ERROR_EXPECTED_ARGUMENT_SEPARATOR.createWithContext(reader); + } + } } catch (final CommandException ex) { errors.put(child, ex); reader.setCursor(cursor); @@ -102,9 +107,6 @@ public class CommandDispatcher { context.withCommand(child.getCommand()); if (reader.canRead()) { - if (reader.peek() != ARGUMENT_SEPARATOR_CHAR) { - throw ERROR_EXPECTED_ARGUMENT_SEPARATOR.createWithContext(reader); - } reader.skip(); if (child.getRedirect() != null) { return parseNodes(child.getRedirect(), reader, context.redirect()); diff --git a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java index df2b29b..3c07fc3 100644 --- a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java +++ b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java @@ -22,6 +22,7 @@ import static org.junit.Assert.fail; import static org.mockito.Matchers.notNull; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -207,6 +208,17 @@ public class CommandDispatcherTest { } } + @Test + public void testExecute_invalidOther() throws Exception { + final Command wrongCommand = mock(Command.class); + subject.register(literal("w").executes(wrongCommand)); + subject.register(literal("world").executes(command)); + + assertThat(subject.execute("world", source), is(42)); + verify(wrongCommand, never()).run(any()); + verify(command).run(any()); + } + @Test public void parse_noSpaceSeparator() throws Exception { subject.register(literal("foo").then(argument("bar", integer()).executes(command)));