Skip to content

Commit 2b4cb29

Browse files
authored
Fix deck names differing in case being duplicated in CSV import (ankitects#3008)
1 parent 23291e7 commit 2b4cb29

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

rslib/src/import_export/text/import.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use std::collections::HashMap;
66
use std::collections::HashSet;
77
use std::sync::Arc;
88

9+
use unicase::UniCase;
10+
911
use super::NameOrId;
1012
use crate::card::CardQueue;
1113
use crate::card::CardType;
@@ -83,7 +85,7 @@ struct Context<'a> {
8385

8486
struct DeckIdsByNameOrId {
8587
ids: HashSet<DeckId>,
86-
names: HashMap<String, DeckId>,
88+
names: HashMap<UniCase<String>, DeckId>,
8789
default: Option<DeckId>,
8890
}
8991

@@ -146,10 +148,10 @@ impl Duplicate {
146148

147149
impl DeckIdsByNameOrId {
148150
fn new(col: &mut Collection, default: &NameOrId) -> Result<Self> {
149-
let names: HashMap<String, DeckId> = col
151+
let names: HashMap<UniCase<String>, DeckId> = col
150152
.get_all_normal_deck_names(false)?
151153
.into_iter()
152-
.map(|(id, name)| (name, id))
154+
.map(|(id, name)| (UniCase::new(name), id))
153155
.collect();
154156
let ids = names.values().copied().collect();
155157
let mut new = Self {
@@ -166,13 +168,13 @@ impl DeckIdsByNameOrId {
166168
match name_or_id {
167169
_ if *name_or_id == NameOrId::default() => self.default,
168170
NameOrId::Id(id) => self.ids.get(&DeckId(*id)).copied(),
169-
NameOrId::Name(name) => self.names.get(name).copied(),
171+
NameOrId::Name(name) => self.names.get(&UniCase::new(name.to_string())).copied(),
170172
}
171173
}
172174

173175
fn insert(&mut self, deck_id: DeckId, name: String) {
174176
self.ids.insert(deck_id);
175-
self.names.insert(name, deck_id);
177+
self.names.insert(UniCase::new(name), deck_id);
176178
}
177179
}
178180

0 commit comments

Comments
 (0)