Repository navigation
fix(deparser): escape single quotes in bit-string literals - #357
Merged
Merged
Conversation
A_Const.bsval (wrapped, unwrapped, val.BitString) and BitString nodes were interpolated raw into b'...'/x'...', so a quote in a programmatically built value closed the literal early. Route all sites through formatBitString, which doubles single quotes like the sval path.
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
This PR extracts duplicated bit-string formatting logic in the deparser into a single
Reviewed commit: 24b7869 |
Contributor
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
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
Fixes #355.
svalgoes throughQuoteUtils.formatEString, butbsvalwas dropped straight intob'...'/x'...'. So if a programmatically built AST had a quote inbsval, it closed the literal early, and whatever followed was emitted as SQL. Parse → deparse round-trips can't hit this, because a parsed bit string never contains a quote.Every bit-string emit site now goes through one helper:
Sites covered:
A_Const: wrappedbsval.bsval, unwrappedbsval, andval.BitString.bsval. That last one used to return the bare value, e.g.b0101, with no quotes at all, which is not valid SQL.BitStringnode visitor.The hex check that
A_Constalready had now applies to theBitStringvisitor too. Anx-prefixed value with non-hex characters falls through to the escapedb'x…'branch; before, the visitor emitted it raw asx'…'.With the fix, the payload from the issue deparses to
SELECT b'x'' OR ''1''=''1'. libpg-query reads that as one literal and rejects it with a syntax error, so nothing gets injected.New tests are in
__tests__/misc/bit-string.test.ts. 6 of them fail onmain. The full deparser suite passes locally.Link to Devin session: https://app.devin.ai/sessions/a1e43e1e9fb2494fa571e6ecb93e1067
Open in Devin Desktop: https://app.devin.ai/desktop/session/a1e43e1e9fb2494fa571e6ecb93e1067?variant=devin
Requested by: @pyramation