From 096b78f8648382c4792411bb83914d1e1d7e0c03 Mon Sep 17 00:00:00 2001 From: Victoria Xia Date: Tue, 7 Jan 2020 11:22:57 -0800 Subject: [PATCH] fix: CLI commands may be terminated with semicolon+whitespace (MINOR) (#4234) --- .../io/confluent/ksql/cli/console/Console.java | 2 +- .../io/confluent/ksql/cli/console/ConsoleTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ksql-cli/src/main/java/io/confluent/ksql/cli/console/Console.java b/ksql-cli/src/main/java/io/confluent/ksql/cli/console/Console.java index 47493f2d5a63..7cc90f5c8799 100644 --- a/ksql-cli/src/main/java/io/confluent/ksql/cli/console/Console.java +++ b/ksql-cli/src/main/java/io/confluent/ksql/cli/console/Console.java @@ -409,7 +409,7 @@ public OutputFormat getOutputFormat() { } private Optional getCliCommand(final String line) { - final List parts = splitByUnquotedWhitespace(StringUtils.stripEnd(line, ";")); + final List parts = splitByUnquotedWhitespace(StringUtils.stripEnd(line.trim(), ";")); if (parts.isEmpty()) { return Optional.empty(); } diff --git a/ksql-cli/src/test/java/io/confluent/ksql/cli/console/ConsoleTest.java b/ksql-cli/src/test/java/io/confluent/ksql/cli/console/ConsoleTest.java index 21e196b14faf..aa8f29638bfd 100644 --- a/ksql-cli/src/test/java/io/confluent/ksql/cli/console/ConsoleTest.java +++ b/ksql-cli/src/test/java/io/confluent/ksql/cli/console/ConsoleTest.java @@ -1356,6 +1356,20 @@ public void shouldSupportCmdBeingTerminatedWithSemiColon() { verify(cliCommand).execute(eq(ImmutableList.of("Arg0")), any()); } + @Test + public void shouldSupportCmdBeingTerminatedWithSemiColonAndWhitespace() { + // Given: + when(lineSupplier.get()) + .thenReturn(CLI_CMD_NAME + WHITE_SPACE + "Arg0; \n") + .thenReturn("not a CLI command;"); + + // When: + console.readLine(); + + // Then: + verify(cliCommand).execute(eq(ImmutableList.of("Arg0")), any()); + } + @Test public void shouldSupportCmdWithQuotedArgBeingTerminatedWithSemiColon() { // Given: