Skip to content

Commit 82a7e24

Browse files
search: properly handle and escape backslashes
1 parent c72b596 commit 82a7e24

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/search_expr.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ fn quoted_string_char(input: &str) -> nom::IResult<&str, char> {
249249
alt((none_of("\\\""), escaped_char))(input)
250250
}
251251

252-
// meant for \" mostly for now
252+
// meant for \" and \\ mostly for now
253253
fn escaped_char(input: &str) -> nom::IResult<&str, char> {
254254
let (input, _) = char('\\')(input)?;
255-
none_of("\\")(input)
255+
anychar(input)
256256
}
257257

258258
fn parse_word(input: &str) -> nom::IResult<&str, String> {
@@ -279,6 +279,14 @@ mod tests {
279279
);
280280
}
281281

282+
#[test]
283+
fn parse_quoted_string_quoted_backslash() {
284+
assert_eq!(
285+
"my \"str\\ing",
286+
parse_quoted_string("\"my \\\"str\\\\ing\"").unwrap().1
287+
);
288+
}
289+
282290
#[test]
283291
fn should_reject_unknown_filter_key() {
284292
assert_eq!(

src/widgets/headerbar_search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl Widget for HeaderbarSearch {
291291
}
292292
if val.contains(' ') || val.contains('"') {
293293
t.push('"');
294-
t.push_str(&val.replace('"', "\\\""));
294+
t.push_str(&val.replace('\\', "\\\\").replace('"', "\\\""));
295295
t.push('"');
296296
} else {
297297
t.push_str(&val);

0 commit comments

Comments
 (0)