From c723adea17b4a6caf5318d1d62e94aa9cacc3e36 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 20 Mar 2020 09:27:19 +1000 Subject: [PATCH] fix escape handling, and handle sql wildcards --- rslib/src/search/parser.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index d60112a2d..03ad4692b 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -174,8 +174,8 @@ fn text(s: &str) -> IResult<&str, Node> { fn search_node_for_text(s: &str) -> ParseResult { let mut it = s.splitn(2, ':'); let (head, tail) = ( - without_escapes(it.next().unwrap()), - it.next().map(without_escapes), + unescape_quotes(it.next().unwrap()), + it.next().map(unescape_quotes), ); if let Some(tail) = tail { @@ -185,10 +185,10 @@ fn search_node_for_text(s: &str) -> ParseResult { } } -/// Strip the \ escaping character -fn without_escapes(s: &str) -> Cow { - if s.find('\\').is_some() { - s.replace('\\', "").into() +/// \" -> " +fn unescape_quotes(s: &str) -> Cow { + if s.find(r#"\""#).is_some() { + s.replace(r#"\""#, "\"").into() } else { s.into() } @@ -216,10 +216,10 @@ fn quoted_term(s: &str) -> IResult<&str, Node> { } /// Quoted text, terminated by a non-escaped double quote -/// Can escape " and \ +/// Can escape %, _, " and \ fn quoted_term_inner(s: &str) -> IResult<&str, Node> { map_res( - escaped(is_not(r#""\"#), '\\', one_of(r#""\"#)), + escaped(is_not(r#""\"#), '\\', one_of(r#""\%_"#)), |o| -> ParseResult { Ok(Node::Search(search_node_for_text(o)?)) }, )(s) }