diff --git a/x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/CliRepl.java b/x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/CliRepl.java index f591ced77ec..956c62eaa1f 100644 --- a/x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/CliRepl.java +++ b/x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/CliRepl.java @@ -56,6 +56,11 @@ public class CliRepl { multiLine.setLength(0); } + // Skip empty commands + if (line.isEmpty()) { + continue; + } + // special case to handle exit if (isExit(line)) { cliTerminal.line().em("Bye!").ln(); diff --git a/x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/CliReplTests.java b/x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/CliReplTests.java index 2397418256a..31aa4749221 100644 --- a/x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/CliReplTests.java +++ b/x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/CliReplTests.java @@ -38,6 +38,28 @@ public class CliReplTests extends ESTestCase { verifyNoMoreInteractions(mockCommand, mockSession); } + /** + * Test that empty commands are skipped. This includes commands that are + * just new lines. + */ + public void testEmptyNotSent() { + CliTerminal cliTerminal = new TestTerminal( + ";", + "", + "", + ";", + "exit;" + ); + + CliSession mockSession = mock(CliSession.class); + CliCommand mockCommand = mock(CliCommand.class); + + CliRepl cli = new CliRepl(cliTerminal, mockSession, mockCommand); + cli.execute(); + + verify(mockCommand, times(1)).handle(cliTerminal, mockSession, "logo"); + verifyNoMoreInteractions(mockSession, mockCommand); + } public void testFatalCliExceptionHandling() throws Exception { CliTerminal cliTerminal = new TestTerminal(