Formatted SQL adds spaces inside the next string literal after a string ending in a backslash
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
- #6507 di @ayushdoesdev — chiusa senza merge
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 38/100
Direzione di ricerca
Start in prqlc/prqlc/src/sql/mod.rs at sql::compile and trace how generated SQL is passed to sqlformat::format; inspect the sqlformat tokenizer behavior described in the issue. Compare the proposed options and add a regression test for the backslash-ending string example. Done means formatted output preserves the literal value; the issue leaves the interim approach and upstream report for maintainers to decide.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
When a string literal in the query ends with a backslash, the formatted SQL (the default output) changes the value of the next string literal by adding spaces inside its quotes. The query then compares against, or selects, a different string than the one written. --no-format output is correct.
prql target:sql.postgres
from files
filter path == 'C:\\' || name == 'readme'
prqlc compile --no-format, which is correct:
SELECT * FROM files WHERE path = 'C:\' OR name = 'readme'
prqlc compile:
SELECT
*
FROM
files
WHERE
path = 'C:\' OR name = ' readme '
name = ' readme ' matches no row that name = 'readme' would. The same happens with derive {a = 'ab\\', b = 'c'}, which emits ' c ' AS b, and with raw strings like r'x\'. Any string whose value ends in a backslash triggers it; the query doesn't have to be unusual.
Cause: sql::compile passes the SQL that sqlparser generates through sqlformat::format. The sqlformat 0.5.0 tokenizer (get_string_token in src/tokenizer.rs) always treats a backslash as an escape inside '...' and "...". So it reads 'C:\' as an unterminated string that runs on to the next '. The quotes then pair up wrongly, and the formatter adds spaces around tokens that are really inside string literals. In standard SQL, and in the Postgres, DuckDB, SQLite and generic dialects PRQL targets, a backslash is an ordinary character, so 'C:\' is a complete literal. FormatOptions::dialect (Generic / PostgreSql / SQLServer) doesn't change this, and 0.5.0 is the latest sqlformat release. I found no report of this in shssoichiro/sqlformat-rs.
Why this is an issue rather than a PR: the durable fix is upstream, in sqlformat's tokenizer, perhaps keyed on its dialect. Any interim change in prqlc is a trade-off a maintainer should pick:
- Skip formatting, and return the unformatted SQL, when the generated SQL contains a backslash. This is simple and can't corrupt values, but those queries lose their layout.
- Mask string literals before formatting and restore them afterwards. This keeps the layout, but adds a second tokenizer pass in prqlc.
Either change would come with a regression test like the example above. Filing the upstream report would also need a decision: the repo shows no agent-contribution policy, so per this repo's tend guidance it waits for a go-ahead here.
- Lingua principale
- Rust
- Stelle
- 10.9k
- Fork
- 261
- Merge medio
- 3g 20h
- PR unite (30g)
- 85
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PRQL/prql
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 3 giorni
-
prqlc Debug Report HTML Does Not Escape Source File Name, Enabling Stored XSS via PRQLC_DEBUG_LOGApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 3 giorni
-
Add `.prql` to linguistApertafriendliness integrations
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
PRQL/prql#1636 · 2 commenti · 2 reazioni ·
I maintainer di solito rispondono entro 3 giorni
-
Creation allowance reachedApertatend-rate-limit
Difficoltà 5/5 Più di una settimana Idoneità per principianti 4/100
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 4/5 1-2 giorni Idoneità per principianti 12/100
I maintainer di solito rispondono entro 3 giorni
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
limitlessprojects/Go-Hybrid#3342 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
librespeed/speedtest-rust#52 · 1 commento ·
-
enhancement needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
bherbruck/solvecraft#11246 · 1 commento · 1 reazione ·
-
example
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
rust-lang-nursery/rust-cookbook#954 ·
I maintainer di solito rispondono entro 1 giorno