Repository navigation
Conversation
…d on always-quoting targets Closes #6562
25e8b23 to
c6a5a52
Compare
prql-bot
left a comment
There was a problem hiding this comment.
The quote stripping in post_process also reaches double quotes inside single-quoted string literals, which changes the string's value on every target; details inline.
prql-bot
left a comment
There was a problem hiding this comment.
The literal-first match fixes the double-quote case from the last round, but an apostrophe in a quoted identifier now pulls a later anchor into a pseudo-literal; details inline.
|
@prql-bot The current head ( Please match the complete quoted token before deciding whether its entire contents are an anchor. For longer tokens, substitute the anchor in place and preserve the identifier quotes and escaped quote. Add a regression for this case.
|
Match each quoted token whole, including escaped quotes, before checking whether its contents are exactly one anchor, so `"_jinja_0_""suffix"` keeps its quotes and escaped quote.
|
Fixed in 1ccbb7e. So |
prql-bot
left a comment
There was a problem hiding this comment.
The new head fixes the escaped-quote prefix case. One regression from main remains in the bracket branch, which predates this push; details inline. I'll push the fix.
No dialect quotes identifiers with [...], so brackets around an anchor
come from SQL such as an s-string index (arr[{{ var('i') }}]) and must
stay. With --no-format the bracket alternative turned that into
arr{{ var('i') }}.
# Conflicts: # CHANGELOG.md
|
@prql-bot At the current head ( Please consume complete dollar-quoted literals (
|
Consume `$$…$$` and `$tag$…$tag$` whole, so a double quote inside one isn't read as an identifier quote around a Jinja anchor.
|
Fixed in ad135fd. The new no-format regression, |
|
@prql-bot The current head (
The exact current function reproduced both in a narrow Rust harness. The quote-token matching does not recognize the escaped apostrophe in the
|
…n prqlc watch output
|
Fixed in 320eb56. The quoted-token regex in
While reproducing, I found one more case in the same code: a
One case is still open, because it depends on the dialect and |
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
prqlc watchreplaces each Jinja interpolation with an identifier-like anchor before compiling, then swaps the anchors back into the SQL. Two things broke that round trip:_jinja_0merged with digits that followed it ({{ ref('orders') }}2024→_jinja_02024). The_jinja_\d+regex then matched an id with no entry, and the anchor was written out unchanged. Anchors now end with_(_jinja_0_), so the regex stops at the anchor's own id and2024stays as text."_jinja_0_"and the interpolation landed inside the quotes ("amount" > "{{ var('min') }}").post_processnow matches each quoted token whole: string literals ('…', and PostgreSQL escape stringsE'…'with backslash escapes and dollar quotes$$…$$/$tag$…$tag$, whose tag may contain non-ASCII letters, while a$that continues an identifier such asa$b$opens no quote) and identifiers ("…",`…`), including their escaped quotes. When an identifier's entire contents are one anchor, the interpolation replaces the identifier along with its quotes, giving"amount" > {{ var('min') }}andFROM {{ ref('orders') }}, the same as the generic target. In every other token, anchors are replaced in place and the quotes stay. String literals therefore keep their quotes, as in'{{ var("n") }}','"{{ var("n") }}"'and$$"{{ var("name") }}"$$. So do identifiers that hold more than the anchor, such as"{{ ref('orders') }}2024"and"_jinja_0_""suffix". An apostrophe inside an identifier ("it's") can't pair with a quote outside it. Brackets are left alone, since no target quotes identifiers with[…], soarr[{{ var('i') }}]from an s-string keeps its brackets.The new tests in
cli/jinja.rsrun the full pre-process → compile → post-process path, orpost_processon hand-written SQL, for each case above.Closes #6562 — automated triage