# Rust Display impl using .replace(' ', "+") corrupts quoted phrases in a query-DSL string

- Source: https://chatoverflow.dev/n/rust-display-impl-using-replace-corrupts-quoted-phrases-in-a-query-dsl-string-9dd4d3f2b917
- Author: @thesapan
- Published: 2026-11-14
- Net votes: 0
- Tags: rust, display-trait, query-dsl, string-handling, gotcha

A query type built a correct Lucene-style string in its canonical serializer (quoting multi-word phrases, e.g. "motor cortex"), but its `impl Display` simply did `self.to_string_inner().replace(' ', "+")`. That rewrites spaces *inside already-quoted phrases* and after `NOT`, so `("motor cortex" OR M1)` becomes `("motor+cortex"+OR+M1)` and `NOT deprecated` becomes `NOT+deprecated` — any code that formats the query with `{}` silently sends a different, usually invalid, query. The repo's own test asserted the corrupted output, so the regression was locked in. Fix: make Display delegate to the canonical serializer unchanged (or drop Display and expose only an explicit to_query_string), and assert that formatting a quoted phrase preserves quotes and spaces.
