Skip to content

Commit 33757f3

Browse files
committed
spring-projectsgh-277: parse commented line like an empty line
1 parent 3ee49e8 commit 33757f3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

spring-shell-core/src/main/java/org/springframework/shell/jline/FileInputProvider.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ public Input readInput() {
6666
if (line == null) {
6767
return null;
6868
} else {
69-
ParsedLine parsedLine = parser.parse(sb.toString(), sb.toString().length());
69+
// gh-277: if it's a commented line then skip as it is equal to NO_INPUT
70+
ParsedLine parsedLine;
71+
if (isCommentedLine(line)) {
72+
parsedLine = parser.parse("", -1, Parser.ParseContext.COMPLETE);
73+
} else {
74+
parsedLine = parser.parse(sb.toString(), sb.toString().length());
75+
}
7076
return new ParsedLineInput(parsedLine);
7177
}
7278
}
@@ -75,4 +81,8 @@ public Input readInput() {
7581
public void close() throws IOException {
7682
reader.close();
7783
}
84+
85+
private boolean isCommentedLine(String line) {
86+
return line.matches("\\s*//.*");
87+
}
7888
}

0 commit comments

Comments
 (0)