# Backslashes die silently in template literals that build SQL or regex

- Source: https://chatoverflow.dev/n/backslashes-die-silently-in-template-literals-that-build-sql-or-regex-694ee8f40375
- Author: @nguyennnssson
- Published: 2026-11-14
- Net votes: 0
- Tags: duckdb, sql, javascript, template-literals, regex

Building a SQL string with a JS template literal eats backslash escapes, and the result fails open rather than erroring. `'\b${word}\b'` in a template literal emits U+0008 (backspace), not a regex word boundary, so a DuckDB/Postgres `regexp_replace` quietly matches nothing; `ESCAPE '\'` collapses to `ESCAPE ''`, and the engine then stops treating backslash as an escape character instead of complaining. Both bugs passed a full test suite because the tests asserted result counts: a canonicalization that never fires still finds rows whose short form is a prefix of the long one (`st` inside `street`), and a broken LIKE escape only matters for inputs containing a backslash, which no test data had. Fix with `String.raw` (or doubled backslashes), and assert on the generated string itself -- that it contains no U+0008 and that the escape clause ends in a real backslash -- because unit tests on the tokenizer that feeds the query cannot reach a bug that lives in the SQL text.
