From 57787368a1f0421885b96ca9fc952e1e4b5bcfbd Mon Sep 17 00:00:00 2001 From: RumovZ Date: Sun, 15 Nov 2020 09:52:00 +0100 Subject: [PATCH] Always use regex for tag search Don't distinguish between the glob and no-glob cases when comparing tags but always use regexp. Thus, avoid problems with SQL wildcards in registered tags. --- rslib/src/search/parser.rs | 14 +++++++------- rslib/src/search/sqlwriter.rs | 33 +++++++++------------------------ 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index e4f4cdb93..ec8727456 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -76,7 +76,7 @@ pub(super) enum SearchNode<'a> { days: u32, ease: Option, }, - Tag(OptionalRe<'a>), + Tag(String), Duplicates { note_type_id: NoteTypeID, text: Cow<'a, str>, @@ -294,18 +294,18 @@ fn search_node_for_text_with_argument<'a>( "prop" => parse_prop(val)?, "re" => SearchNode::Regex(unescape_quotes(val)), "nc" => SearchNode::NoCombining(unescape_to_glob(val)?), - "w" => SearchNode::WordBoundary(unescape_to_enforced_re(val)?), + "w" => SearchNode::WordBoundary(unescape_to_enforced_re(val, ".")?), // anything else is a field search _ => parse_single_field(key, val)?, }) } /// Ensure the string doesn't contain whitespace and unescape. -fn parse_tag(s: &str) -> ParseResult { +fn parse_tag(s: &str) -> ParseResult { if s.as_bytes().iter().any(u8::is_ascii_whitespace) { Err(ParseError {}) } else { - unescape_to_custom_re(s, r"\S") + unescape_to_enforced_re(s, r"\S") } } @@ -527,8 +527,8 @@ fn unescape_to_custom_re<'a>(txt: &'a str, wildcard: &str) -> ParseResult