Move whitespace check for tags from to sqlwriter

Instead of not parsing a tag containing whitespace, check for spaces
when writing sql and if there are any, explicitly match nothing.
This commit is contained in:
RumovZ 2020-11-15 11:54:21 +01:00
parent 57787368a1
commit 63cc877023
2 changed files with 5 additions and 10 deletions

View File

@ -281,7 +281,7 @@ fn search_node_for_text_with_argument<'a>(
"edited" => SearchNode::EditedInDays(val.parse()?),
"deck" => SearchNode::Deck(unescape_quotes(val)),
"note" => SearchNode::NoteType(unescape_to_re(val)?),
"tag" => SearchNode::Tag(parse_tag(val)?),
"tag" => SearchNode::Tag(unescape_to_enforced_re(val, r"\S")?),
"mid" => SearchNode::NoteTypeID(val.parse()?),
"nid" => SearchNode::NoteIDs(check_id_list(val)?),
"cid" => SearchNode::CardIDs(check_id_list(val)?),
@ -300,15 +300,6 @@ fn search_node_for_text_with_argument<'a>(
})
}
/// Ensure the string doesn't contain whitespace and unescape.
fn parse_tag(s: &str) -> ParseResult<String> {
if s.as_bytes().iter().any(u8::is_ascii_whitespace) {
Err(ParseError {})
} else {
unescape_to_enforced_re(s, r"\S")
}
}
/// ensure a list of ids contains only numbers and commas, returning unchanged if true
/// used by nid: and cid:
fn check_id_list(s: &str) -> ParseResult<&str> {

View File

@ -189,6 +189,9 @@ impl SqlWriter<'_> {
}
fn write_tag(&mut self, s: &String) -> Result<()> {
if s.contains(" ") {
write!(self.sql, "false").unwrap();
} else {
match s.as_str() {
"none" => write!(self.sql, "n.tags = ''").unwrap(),
r"\S*" => write!(self.sql, "true").unwrap(),
@ -197,6 +200,7 @@ impl SqlWriter<'_> {
self.args.push(format!("(?i).* {} .*", s));
}
}
}
Ok(())
}