From b5159dffbe48248f751fe1ba91335c494a32535c Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Mon, 12 Jun 2023 09:05:30 +0100 Subject: [PATCH] Revert "ExtendedDefaultParser should not add empty arguments" This reverts commit c1c9f5e2c20d8b7ebb35cce8ae40609cbb7617e5. Relates #765 --- .../shell/jline/ExtendedDefaultParser.java | 17 +++--- .../jline/ExtendedDefaultParserTests.java | 52 ------------------- 2 files changed, 7 insertions(+), 62 deletions(-) delete mode 100644 spring-shell-core/src/test/java/org/springframework/shell/jline/ExtendedDefaultParserTests.java diff --git a/spring-shell-core/src/main/java/org/springframework/shell/jline/ExtendedDefaultParser.java b/spring-shell-core/src/main/java/org/springframework/shell/jline/ExtendedDefaultParser.java index aa783c1f..5e6dc26e 100644 --- a/spring-shell-core/src/main/java/org/springframework/shell/jline/ExtendedDefaultParser.java +++ b/spring-shell-core/src/main/java/org/springframework/shell/jline/ExtendedDefaultParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2023 the original author or authors. + * Copyright 2017-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -125,26 +125,23 @@ public class ExtendedDefaultParser implements Parser { } } - if (current.length() > 0 || (line != null && cursor == line.length())) { - if (current.length() > 0) { - words.add(current.toString()); - } + if (current.length() > 0 || cursor == line.length()) { + words.add(current.toString()); } - if (line != null && cursor == line.length() && words.size() > 0) { + if (cursor == line.length()) { wordIndex = words.size() - 1; wordCursor = words.get(words.size() - 1).length(); } - if (eofOnEscapedNewLine && (line != null && isEscapeChar(line, line.length() - 1))) { + if (eofOnEscapedNewLine && isEscapeChar(line, line.length() - 1)) { throw new EOFError(-1, -1, "Escaped new line", "newline"); } if (eofOnUnclosedQuote && quoteStart >= 0 && context != ParseContext.COMPLETE) { - throw new EOFError(-1, -1, "Missing closing quote", - (line != null && line.charAt(quoteStart) == '\'') ? "quote" : "dquote"); + throw new EOFError(-1, -1, "Missing closing quote", line.charAt(quoteStart) == '\'' ? "quote" : "dquote"); } - String openingQuote = (quoteStart >= 0 && line != null) ? line.substring(quoteStart, quoteStart + 1) : null; + String openingQuote = quoteStart >= 0 ? line.substring(quoteStart, quoteStart + 1) : null; return wrap(new ExtendedArgumentList(line, words, wordIndex, wordCursor, cursor, openingQuote)); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/jline/ExtendedDefaultParserTests.java b/spring-shell-core/src/test/java/org/springframework/shell/jline/ExtendedDefaultParserTests.java deleted file mode 100644 index aa60282c..00000000 --- a/spring-shell-core/src/test/java/org/springframework/shell/jline/ExtendedDefaultParserTests.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.shell.jline; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ExtendedDefaultParserTests { - - @Test - void wordsParsing() { - ExtendedDefaultParser parser = new ExtendedDefaultParser(); - - assertThat(parser.parse("one", 0).words()).hasSize(1); - assertThat(parser.parse("one", 3).words()).hasSize(1); - - assertThat(parser.parse("one two", 0).words()).hasSize(2); - assertThat(parser.parse("one two", 7).words()).hasSize(2); - - assertThat(parser.parse("'one'", 0).words()).hasSize(1); - assertThat(parser.parse("'one'", 5).words()).hasSize(1); - - assertThat(parser.parse("'one' two", 0).words()).hasSize(2); - assertThat(parser.parse("'one' two", 9).words()).hasSize(2); - - assertThat(parser.parse("one 'two'", 0).words()).hasSize(2); - assertThat(parser.parse("one 'two'", 9).words()).hasSize(2); - - assertThat(parser.parse("\"one\"", 0).words()).hasSize(1); - assertThat(parser.parse("\"one\"", 5).words()).hasSize(1); - - assertThat(parser.parse("\"one\" two", 0).words()).hasSize(2); - assertThat(parser.parse("\"one\" two", 9).words()).hasSize(2); - - assertThat(parser.parse("one \"two\"", 0).words()).hasSize(2); - assertThat(parser.parse("one \"two\"", 9).words()).hasSize(2); - } -}