fix: escape quotes when both quote types are at string boundaries#5987
Open
prql-bot wants to merge 1 commit into
Open
fix: escape quotes when both quote types are at string boundaries#5987prql-bot wants to merge 1 commit into
prql-bot wants to merge 1 commit into
Conversation
`quote_string` chooses single or double quotes to avoid escaping, but when a string contains both quote characters at its boundaries (e.g. starts with `"` and ends with `'`), neither bare delimiter round-trips — the boundary quote merges with the delimiter because the lexer counts opening/closing quotes greedily. This produced output the lexer could not parse back. Fall back to escaping double-quotes in that case (only for non-raw strings, which support escapes). Adds a regression test that round-trips the affected strings through the lexer. Co-Authored-By: Claude Opus 4.8 <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.
Problem
Literal::String'sDisplay(viaquote_stringinlexer/lr.rs) picks single or double quotes to avoid escaping. When a string contains both quote characters and one is at each boundary — e.g. starts with"and ends with'— neither bare delimiter round-trips:multi_quoted_stringinlexer/mod.rs), so a quote at the string boundary merges with the chosen delimiter."x'formatted as'''"x'''', which the lexer rejects).This was a known gap — there was a
TODOinquote_stringnoting the case was unhandled and untested.Fix
When both quote characters appear at a boundary so no bare delimiter works, fall back to a double-quoted string with embedded
"escaped as\". This only applies to normal strings (raw strings have no escape mechanism; such content has no raw-string representation in the first place).The common cases that motivate the quote-switching (e.g.
he's nice→"he's nice",he said "what up"→'he said "what up"') are unchanged.Tests
test_string_quoting_both_boundary_quotes— snapshots the new escaped output.test_string_roundtrip_boundary— round-trips the affected strings through the lexer, failing before this fix.🤖 Generated with Claude Code