From 2b4cb2992b39a2b7558de3c158b6050c2f3e0556 Mon Sep 17 00:00:00 2001 From: Abdo Date: Wed, 14 Feb 2024 13:25:54 +0300 Subject: [PATCH] Fix deck names differing in case being duplicated in CSV import (#3008) --- rslib/src/import_export/text/import.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/rslib/src/import_export/text/import.rs b/rslib/src/import_export/text/import.rs index 8c70ce749..6b332a651 100644 --- a/rslib/src/import_export/text/import.rs +++ b/rslib/src/import_export/text/import.rs @@ -6,6 +6,8 @@ use std::collections::HashMap; use std::collections::HashSet; use std::sync::Arc; +use unicase::UniCase; + use super::NameOrId; use crate::card::CardQueue; use crate::card::CardType; @@ -83,7 +85,7 @@ struct Context<'a> { struct DeckIdsByNameOrId { ids: HashSet, - names: HashMap, + names: HashMap, DeckId>, default: Option, } @@ -146,10 +148,10 @@ impl Duplicate { impl DeckIdsByNameOrId { fn new(col: &mut Collection, default: &NameOrId) -> Result { - let names: HashMap = col + let names: HashMap, DeckId> = col .get_all_normal_deck_names(false)? .into_iter() - .map(|(id, name)| (name, id)) + .map(|(id, name)| (UniCase::new(name), id)) .collect(); let ids = names.values().copied().collect(); let mut new = Self { @@ -166,13 +168,13 @@ impl DeckIdsByNameOrId { match name_or_id { _ if *name_or_id == NameOrId::default() => self.default, NameOrId::Id(id) => self.ids.get(&DeckId(*id)).copied(), - NameOrId::Name(name) => self.names.get(name).copied(), + NameOrId::Name(name) => self.names.get(&UniCase::new(name.to_string())).copied(), } } fn insert(&mut self, deck_id: DeckId, name: String) { self.ids.insert(deck_id); - self.names.insert(name, deck_id); + self.names.insert(UniCase::new(name), deck_id); } }