Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jline.reader.Parser;
import org.springframework.shell.Input;
import org.springframework.shell.InputProvider;
import org.springframework.util.StringUtils;

import java.io.BufferedReader;
import java.io.Closeable;
Expand All @@ -33,6 +34,7 @@
* of line to signal line continuation.</p>
*
* @author Eric Bottard
* @author David Pilar
*/
public class FileInputProvider implements InputProvider, Closeable {

Expand Down Expand Up @@ -63,9 +65,13 @@ public Input readInput() {
} catch (IOException e) {
throw new RuntimeException(e);
}
if (line == null || isComment(line)) {
if (line == null) {
return null;
} else {
}
else if (!StringUtils.hasLength(line) || isComment(line)) {
return readInput();
}
else {
ParsedLine parsedLine = parser.parse(sb.toString(), sb.toString().length());
return new ParsedLineInput(parsedLine);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@

import org.jline.reader.EOFError;
import org.jline.reader.impl.DefaultParser;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import org.springframework.shell.Input;

import java.io.Reader;
import java.io.StringReader;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -98,4 +103,27 @@ void shouldNotThrowOnUnclosedQuoteExtendedParser(String line) {
fileInputProvider.readInput();
});
}

@Test
void shouldSkipEmptyAndCommentedLines() {
String inputContent = """
echo Hello World
// This is a comment
echo Line 1\\
Line 2

echo Line 3""";
Reader reader = new StringReader(inputContent);
fileInputProvider = new FileInputProvider(reader, springParser);

Input first = fileInputProvider.readInput();
Input second = fileInputProvider.readInput();
Input third = fileInputProvider.readInput();
Input fourth = fileInputProvider.readInput();

assertEquals("echo Hello World", first.rawText());
assertEquals("echo Line 1 Line 2", second.rawText());
assertEquals("echo Line 3", third.rawText());
assertNull(fourth);
}
}