Skip to content

Commit

Permalink
need to escape \ still?
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Sep 26, 2024
1 parent 19f8243 commit 19ba376
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/sql/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,14 @@ impl<'a, W: Write> Serializer for ParamSerializer<'a, W> {
fn serialize_str(self, value: &str) -> Result {
// ClickHouse expects strings in params to be unquoted until inside a nested type
// nested types go through serialize_seq which'll quote strings
self.writer.write_str(value)?;
let mut rest = value;
while let Some(nextidx) = rest.find('\\') {
let (before, after) = rest.split_at(nextidx + 1);
rest = after;
self.writer.write_str(before)?;
self.writer.write_char('\\')?;
}
self.writer.write_str(rest)?;
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions tests/it/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ async fn server_side_param() {

let result = client
.query("SELECT {val1: String} AS result")
.with_param("val1", "\x01\x02\x03\\\"\'")
.with_param("val1", "\x01\x02\x03\\ \"\'")
.expect("failed to bind weird string")
.fetch_one::<String>()
.await
.expect("failed to fetch string");
assert_eq!(result, "\x01\x02\x03\\\"\'");
assert_eq!(result, "\x01\x02\x03\\ \"\'");

let result = client
.query("SELECT {val1: Array(String)} AS result")
Expand Down

0 comments on commit 19ba376

Please sign in to comment.