Repository navigation
Conversation
namtzigla
force-pushed
the
fix/placeholder-parser-literal-comment-aware
branch
from
July 22, 2026 03:42
1306eea to
ab1e81c
Compare
…omments
The query formatter scanned for '?' with a plain byte search, so a '?' that
appears inside a string literal or a comment in the query template was mistaken
for a bind placeholder. That consumed a positional argument and silently shifted
every subsequent binding, e.g.
NewRaw("... WHERE note='huh?' AND org_id=? AND secret=?", 42, "s3cr3t")
=> ... WHERE note='huh42' AND org_id='s3cr3t' AND secret=?
org_id receives the wrong value and the last placeholder dangles.
Add Parser.ReadUntilPlaceholder, a literal/comment-aware replacement for
ReadSep('?'): it skips '...'/"..." quoted strings (with doubled-quote escaping),
-- line comments, and nesting /* */ block comments. It is deliberately
conservative so it never skips a genuine placeholder: backslash escaping inside
literals is not interpreted (matches standard_conforming_strings=on) and
dollar-/E-strings degrade to the previous behaviour rather than over-consuming.
namtzigla
force-pushed
the
fix/placeholder-parser-literal-comment-aware
branch
from
July 22, 2026 03:50
ab1e81c to
71b8288
Compare
|
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this pr will be closed. Please feel free to give a status update now, ping for review, when it's ready. Thank you for your contributions! |
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.
What
Makes the query placeholder parser aware of string literals and comments, so a
?inside a
'...'/"..."literal or a--//* */comment is no longer mistaken for abind placeholder.
Closes #1399.
Why
The formatter scanned for
?with a plain byte search (ReadSep('?')), so a?in aliteral or comment consumed a positional argument and shifted every subsequent binding:
Change
Parser.ReadUntilPlaceholder(internal/parser): a literal/comment-awarereplacement for
ReadSep('?'). It skips'...'/"..."quoted strings (with doubled-quoteescaping),
--line comments, and nesting/* */block comments.schema/querygen.go: useReadUntilPlaceholder()instead ofReadSep('?')(one line).The scanner is deliberately conservative so it can never skip a genuine placeholder:
backslash escaping inside literals is not interpreted (matches
standard_conforming_strings=on, the default since PG 9.1), and$$...$$/E'...'stringsdegrade to the previous behavior rather than over-consuming. The existing
\?escape andnamed/positional argument handling are unchanged.
Tests
internal/parser: unit tests forReadUntilPlaceholder(literals, doubled quotes,quoted identifiers, line/nested-block comments, placeholder-before-literal).
schema: formatter-level regression test asserting exact output; it fails on the oldReadSepbehavior and passes with the fix. Fullgo test ./internal/... ./schema/... .passes;
gofmt/go vetclean.