Skip to content

Commit

Permalink
Allow for multiple spaces between arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Fortern committed Aug 12, 2024
1 parent d2e25c1 commit 4c8d2ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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 @@ -325,7 +325,9 @@ private ParseResults<S> parseNodes(final CommandNode<S> node, final StringReader

context.withCommand(child.getCommand());
if (reader.canRead(child.getRedirect() == null ? 2 : 1)) {
reader.skip();
do {
reader.skip();
} while (reader.canRead() && reader.peek() == ARGUMENT_SEPARATOR_CHAR);
if (child.getRedirect() != null) {
final CommandContextBuilder<S> childContext = new CommandContextBuilder<>(this, source, child.getRedirect(), reader.getCursor());
final ParseResults<S> parse = parseNodes(child.getRedirect(), reader, childContext);
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/mojang/brigadier/CommandDispatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,15 @@ public void parse_noSpaceSeparator() {
}
}

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

assertThat(subject.execute("foo bar", source), is(42));
verify(command).run(any(CommandContext.class));
}

@Test
public void testExecuteInvalidSubcommand() {
subject.register(literal("foo").then(
Expand Down

0 comments on commit 4c8d2ab

Please sign in to comment.