Skip to content

Commit

Permalink
[SQLLINE-318] Correct highlighting and line continuation for '/*/'
Browse files Browse the repository at this point in the history
  • Loading branch information
snuyanzin committed Jul 10, 2019
1 parent 104abc8 commit a672fdf
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/sqlline/SqlLineHighlighter.java
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ int handleComments(String line, BitSet commentBitSet,
if (startingPoint + 1 < line.length()
&& ch == '/'
&& line.charAt(startingPoint + 1) == '*') {
int end = line.indexOf("*/", startingPoint);
int end = startingPoint + 2 < line.length()
? line.indexOf("*/", startingPoint + 2) : -1;
end = end == -1 ? line.length() - 1 : end + 1;
commentBitSet.set(startingPoint, end + 1);
startingPoint = end;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/sqlline/SqlLineParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public ParsedLine parse(final String line, final int cursor,
rawWordLength, rawWordStart, i);
rawWordStart = i + 1;
} else if (multiLineCommentStart >= 0) {
if (currentChar == '/' && line.charAt(i - 1) == '*') {
if (i - multiLineCommentStart > 2
&& currentChar == '/' && line.charAt(i - 1) == '*') {
// End the block; arg could be empty, but that's fine
words.add(flush(current));
multiLineCommentStart = -1;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/sqlline/SqlLineHighlighterLowLevelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public void testLowLevelHandleComments() {
"--select",
"/* \"''\"",
"/*",
"/*/ should be a comment",
"--",
"/* kh\n'asd'ad*/",
"/*\"-- \"values*/"
Expand Down
1 change: 1 addition & 0 deletions src/test/java/sqlline/SqlLineHighlighterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public void testCommentedStrings() {
"--select",
"/* \"''\"",
"/*",
"/*/ should be a comment",
"--",
"--\n/*",
"/* kh\n'asd'ad*/",
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/sqlline/SqlLineParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class SqlLineParserTest {
"select 1 --; --;",
"select /*--\n\n--\n--;",
"select /* \n ;",
"select /*/;",
"select --\n/*\n--\n--;",
"select ' ''\n '' '\n /* ;",
"select ` ``\n `` `\n /* ;",
Expand Down Expand Up @@ -182,7 +183,7 @@ public void testSqlLineParserForWrongLinesWithEmptyPrompt() {
for (String line : WRONG_LINES) {
try {
parser.parse(line, line.length(), acceptLine);
fail("Missing closing quote or semicolon for line " + line);
fail("Missing closing comment, quote or semicolon for line " + line);
} catch (EOFError eofError) {
//ok
}
Expand Down

0 comments on commit a672fdf

Please sign in to comment.