Skip to content

fix(sql): handle unbalanced quotes in SQL line comments#6684

Merged
bluestreak01 merged 3 commits intomasterfrom
vi_lexer_fix
Jan 20, 2026
Merged

fix(sql): handle unbalanced quotes in SQL line comments#6684
bluestreak01 merged 3 commits intomasterfrom
vi_lexer_fix

Conversation

@bluestreak01
Copy link
Copy Markdown
Member

Summary

Fixes #6671

When a SQL line comment contains an unbalanced single quote (e.g., -- magic '), the lexer enters string-parsing mode and incorrectly consumes tokens past the newline, causing subsequent SQL tokens to be lost from the query.

Root cause: The GenericLexer treats ' as the start of a string literal regardless of context. When SqlUtil.fetchNext() is in line comment mode and receives a token that spans across a newline (because the lexer consumed it as part of a quoted string), the simple newline check Chars.equals(cs, '\n') fails since the token is a multi-character string.

Fix: When in line comment mode, check if the token contains a newline character. If found, reposition the lexer to just after the newline using backTo() to properly reset the lexer state.

Test plan

  • Added testLineCommentWithUnbalancedQuote test that reproduces the issue
  • All existing GenericLexerTest tests pass (39 tests)

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 20, 2026

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 11 / 18 (61.11%)

file detail

path covered line new line coverage
🔵 io/questdb/griffin/SqlUtil.java 11 18 61.11%

@bluestreak01 bluestreak01 merged commit fc3f734 into master Jan 20, 2026
43 checks passed
@bluestreak01 bluestreak01 deleted the vi_lexer_fix branch January 20, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

filter disappears when comment is added to a query

2 participants