diff --git a/rslib/src/tags.rs b/rslib/src/tags.rs index 2a91013b9..7513fecac 100644 --- a/rslib/src/tags.rs +++ b/rslib/src/tags.rs @@ -334,7 +334,7 @@ impl Collection { let tags = split_tags(tags) .map(|tag| { let tag = if regex { tag.into() } else { to_re(tag) }; - Regex::new(&format!("(?i)^{}(::.*)?", tag)) + Regex::new(&format!("(?i)^{}(::.*)?$", tag)) .map_err(|_| AnkiError::invalid_input("invalid regex")) }) .collect::>>()?; @@ -566,6 +566,14 @@ mod test { let note = col.storage.get_note(note.id)?.unwrap(); assert_eq!(¬e.tags, &["foo::bar", "foo::bar::bar", "foo::bar::foo",]); + // ensure replacements fully match + let mut note = col.storage.get_note(note.id)?.unwrap(); + note.tags = vec!["foobar".into(), "barfoo".into(), "foo".into()]; + col.update_note(&mut note)?; + col.replace_tags_for_notes(&[note.id], "foo", "", false)?; + let note = col.storage.get_note(note.id)?.unwrap(); + assert_eq!(¬e.tags, &["barfoo", "foobar"]); + // tag children are also cleared when clearing their parent col.storage.clear_tags()?; for name in vec!["a", "a::b", "A::b::c"] {