diff --git a/src/search_expr.rs b/src/search_expr.rs index 7dd98f2..ed0b705 100644 --- a/src/search_expr.rs +++ b/src/search_expr.rs @@ -249,10 +249,10 @@ fn quoted_string_char(input: &str) -> nom::IResult<&str, char> { alt((none_of("\\\""), escaped_char))(input) } -// meant for \" mostly for now +// meant for \" and \\ mostly for now fn escaped_char(input: &str) -> nom::IResult<&str, char> { let (input, _) = char('\\')(input)?; - none_of("\\")(input) + anychar(input) } fn parse_word(input: &str) -> nom::IResult<&str, String> { @@ -279,6 +279,14 @@ mod tests { ); } + #[test] + fn parse_quoted_string_quoted_backslash() { + assert_eq!( + "my \"str\\ing", + parse_quoted_string("\"my \\\"str\\\\ing\"").unwrap().1 + ); + } + #[test] fn should_reject_unknown_filter_key() { assert_eq!( diff --git a/src/widgets/headerbar_search.rs b/src/widgets/headerbar_search.rs index 5b37297..ebdc178 100644 --- a/src/widgets/headerbar_search.rs +++ b/src/widgets/headerbar_search.rs @@ -291,7 +291,7 @@ impl Widget for HeaderbarSearch { } if val.contains(' ') || val.contains('"') { t.push('"'); - t.push_str(&val.replace('"', "\\\"")); + t.push_str(&val.replace('\\', "\\\\").replace('"', "\\\"")); t.push('"'); } else { t.push_str(&val);