Escape newlines in sqlString so multiline rowConditions produce valid SQL#2214
Open
ihistand wants to merge 2 commits into
Open
Escape newlines in sqlString so multiline rowConditions produce valid SQL#2214ihistand wants to merge 2 commits into
ihistand wants to merge 2 commits into
Conversation
A multiline `rowConditions` entry compiled to an invalid `failing_row_condition` string literal, because BigQuery single-quoted literals cannot span multiple lines (issue dataform-co#2201). `sqlString` only escaped backslashes and single quotes, so a raw newline survived into the quoted label. Escape newlines/carriage-returns too, after backslash escaping so the introduced escapes are not themselves doubled. The raw `WHERE NOT (...)` clause is untouched.
Compiles a table with a multiline rowConditions entry and asserts the failing_row_condition literal stays single-line (escaped \n) while the WHERE NOT (...) clause keeps the raw multiline expression. Covers dataform-co#2201.
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 #2201.
Problem
A multiline
rowConditionsentry compiles to invalid SQL:rowConditionsAssertionembeds the condition twice: once raw insideWHERE NOT (...)(fine — multiline is valid there), and once as a string-literal label viasqlString(...).sqlStringonly escaped backslashes and single quotes, so a raw newline survived into the single-quotedfailing_row_conditionliteral — which BigQuery rejects, since single-quoted literals can't span multiple lines.Fix
The bug belongs in
sqlString, not the assertion template — any caller that quotes a multiline string hits it.sqlStringnow also escapes newlines/carriage-returns, turning a raw newline into the two-char\nescape (which parses back to a newline, keeping the literal single-line):Ordering matters: backslash-doubling runs first, otherwise the
\n/\rintroduced here would themselves get re-escaped into\\n/\\rand print a literal backslash-n.The raw
WHERE NOT (...)clause is untouched — the multiline expression stays as-authored; only the label literal is normalized:Why escape over triple-quoting (the issue's other suggestion): escaping reuses the quote-escaping path already in
sqlString, so one code path handles quotes, backslashes, and newlines uniformly. Triple-quoting would need its own rules for embedded'''.Test
Added a regression test in
core/actions/assertion_test.tsthat compiles a table with a multilinerowConditionsentry and asserts thefailing_row_conditionliteral stays single-line (escaped\n) while theWHERE NOT (...)clause keeps the raw, multiline expression.This was raised in #2201 and a maintainer invited a PR. Happy to adjust style or placement.