fix(sqlite): non-ASCII in SQL comments corrupts generated queries#4373
Open
exploded wants to merge 1 commit intosqlc-dev:mainfrom
Open
fix(sqlite): non-ASCII in SQL comments corrupts generated queries#4373exploded wants to merge 1 commit intosqlc-dev:mainfrom
exploded wants to merge 1 commit intosqlc-dev:mainfrom
Conversation
…ce extraction ANTLR's InputStream operates on characters (runes), so token positions returned by GetStop() are character indices. However, source.Pluck() slices Go strings using byte offsets. When multi-byte UTF-8 characters (e.g. em-dash U+2014) appear in SQL comments, this mismatch causes queries to be extracted at wrong positions -- truncating parameter placeholders and leaking comment text into generated Go code. Build a rune-to-byte offset lookup table and use it to translate ANTLR positions before storing StmtLocation and StmtLen. Fixes sqlc-dev#4372 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
InputStreamoperates on characters (runes), so token positions are character indices.source.Pluck()slices Go strings with byte offsets. When multi-byte UTF-8 characters (e.g. em-dash U+2014, 3 bytes) appear in SQL comments, the offset mismatch causes query text to be extracted at wrong positions -- truncating?parameter placeholders and leaking comment text into generated Go code.StmtLocation/StmtLen.sqlite_unicode_commentreproducing the exact scenario from the issue (em-dash in a comment between two queries).Fixes #4372
Test plan
sqlite_unicode_commentpassessqlite_skip_todo,sqlite_table_options)TestReplay/basesuite passes (only pre-existingwasm_plugin_sqlc_gen_unsafe_pathsfailure, unrelated)🤖 Generated with Claude Code