Skip to content

Commit ecf69cf

Browse files
author
Jon Petersson
committed
Prevent duplicate list names in custom lists
1 parent b2c94cc commit ecf69cf

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ios/MullvadSettings/CustomListRepository.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ public struct CustomListRepository: CustomListRepositoryProtocol {
3939
public func save(list: CustomList) throws {
4040
var lists = fetchAll()
4141

42-
if let index = lists.firstIndex(where: { $0.id == list.id }) {
42+
let persistedListWithSameName = lists.first {
43+
$0.name.localizedCaseInsensitiveCompare(list.name) == .orderedSame
44+
}
45+
46+
if let persistedListWithSameName, persistedListWithSameName.id != list.id {
47+
throw CustomRelayListError.duplicateName
48+
} else if let index = lists.firstIndex(where: { $0.id == list.id }) {
4349
lists[index] = list
4450
try write(lists)
45-
} else if lists.contains(where: { $0.name == list.name }) {
46-
throw CustomRelayListError.duplicateName
4751
} else {
4852
lists.append(list)
4953
try write(lists)

0 commit comments

Comments
 (0)