mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
fix deck and tag normalization
The issue existed in the deck code as well; I've added a test for it.
This commit is contained in:
parent
09bea954a2
commit
9edb002679
2 changed files with 26 additions and 7 deletions
|
@ -114,10 +114,11 @@ fn normalize_native_name(name: &str) -> Cow<str> {
|
|||
.split('\x1f')
|
||||
.any(|comp| matches!(normalized_deck_name_component(comp), Cow::Owned(_)))
|
||||
{
|
||||
name.split('\x1f')
|
||||
let comps: Vec<_> = name
|
||||
.split('\x1f')
|
||||
.map(normalized_deck_name_component)
|
||||
.collect::<String>()
|
||||
.into()
|
||||
.collect::<Vec<_>>();
|
||||
comps.join("\x1f").into()
|
||||
} else {
|
||||
// no changes required
|
||||
name.into()
|
||||
|
@ -525,7 +526,7 @@ impl Collection {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{human_deck_name_to_native, immediate_parent_name};
|
||||
use super::{human_deck_name_to_native, immediate_parent_name, normalize_native_name};
|
||||
use crate::{
|
||||
collection::{open_test_collection, Collection},
|
||||
err::Result,
|
||||
|
@ -562,6 +563,12 @@ mod test {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize() {
|
||||
assert_eq!(&normalize_native_name("foo\x1fbar"), "foo\x1fbar");
|
||||
assert_eq!(&normalize_native_name("fo\u{a}o\x1fbar"), "foo\x1fbar");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn adding_updating() -> Result<()> {
|
||||
let mut col = open_test_collection();
|
||||
|
|
|
@ -91,10 +91,11 @@ fn normalize_tag_name(name: &str) -> Cow<str> {
|
|||
.split("::")
|
||||
.any(|comp| matches!(normalized_tag_name_component(comp), Cow::Owned(_)))
|
||||
{
|
||||
name.split("::")
|
||||
let comps: Vec<_> = name
|
||||
.split("::")
|
||||
.map(normalized_tag_name_component)
|
||||
.collect::<String>()
|
||||
.into()
|
||||
.collect::<Vec<_>>();
|
||||
comps.join("::").into()
|
||||
} else {
|
||||
// no changes required
|
||||
name.into()
|
||||
|
@ -419,6 +420,17 @@ mod test {
|
|||
col.update_note(&mut note)?;
|
||||
assert_eq!(¬e.tags, &["one", "two"]);
|
||||
|
||||
// blanks should be handled
|
||||
note.tags = vec![
|
||||
"".into(),
|
||||
"foo".into(),
|
||||
" ".into(),
|
||||
"::".into(),
|
||||
"foo::".into(),
|
||||
];
|
||||
col.update_note(&mut note)?;
|
||||
assert_eq!(¬e.tags, &["blank::blank", "foo", "foo::blank"]);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue