Skip to content

Commit c3d575e

Browse files
Jon Peterssonbuggmagnet
Jon Petersson
authored andcommitted
Prevent duplicate list names in custom lists
1 parent 8f8bd1d commit c3d575e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

ios/MullvadSettings/CustomListRepository.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ 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+
if let listWithSameName = lists.first(where: { $0.name.caseInsensitiveCompare(list.name) == .orderedSame }),
43+
listWithSameName.id != list.id {
44+
throw CustomRelayListError.duplicateName
45+
} else if let index = lists.firstIndex(where: { $0.id == list.id }) {
4346
lists[index] = list
4447
try write(lists)
45-
} else if lists.contains(where: { $0.name == list.name }) {
46-
throw CustomRelayListError.duplicateName
4748
} else {
4849
lists.append(list)
4950
try write(lists)

0 commit comments

Comments
 (0)