fix(params): strip $action as a whole token, not a substring - #329
Merged
Conversation
const db = createTypedDb<DB, { placeholders: 'question' }>(executor);
db.query('select id from users where kind = $actionType', 'x'); // compiled
Any `$name` starting with "action" escaped the placeholder-style check.
StripDollarAction removed the substring `$action` anywhere, so `$actiontype`
became `type` before the dollar scan ran, UsedPlaceholderStyles came back
`never`, and the brand accepted every dialect - while Params still assigned
the token a slot. A mysql or sqlite driver cannot bind a `$name`, so this is
exactly the guaranteed runtime failure the brand exists to prevent.
The strip now keeps `$action` when an identifier character follows it, which
is the rule IsPlaceholder already applies on the other side (it excludes only
the exact token). A real `output $action, inserted.id` is followed by a
comma, so MERGE is unaffected.
Fixes #298
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tiagolauer
force-pushed
the
fix/298-dollar-action-token
branch
from
August 2, 2026 13:03
5ee0cea to
6ad5f73
Compare
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.
Fixes #298.
The bug
UsedPlaceholderStylescame backneverfor that query, so the brand check passed for any dialect, whileParamsstill assigned the token a[string]slot. A mysql or sqlite driver can never bind a$name, so this is exactly the guaranteed runtime failure the brand exists to prevent. Same for$action_id,$actionable, and friends.The fix
The two layers disagreed about what
$actionmeans.StripDollarActionremoved the substring anywhere, so$actiontypebecametypebefore the dollar scan ran;IsPlaceholderexcludes only the exact token. The strip now followsIsPlaceholder's rule: keep$actionwhen an identifier character follows it.MERGE is unaffected — a real
output $action, inserted.idhas a comma after it, andtests/dialect-mssql.test-d.tspins that (the pseudo-column takes no parameter slot and does not make the statement look dollar-styled).Verification
tests/dialect-brand.test-d.ts, four new cases. The three@ts-expect-errorones are red on master, whichtscreports precisely because the directive is unused there:$actionType,$action_idand$actionable$actionTypetsc --noEmitclean, budget 192,568 (+82).