Skip to content

Commit c283112

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

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ios/MullvadSettings/CustomListRepository.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ 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 lists.contains(where: { $0.name.localizedCaseInsensitiveCompare(list.name) == .orderedSame }) {
43+
throw CustomRelayListError.duplicateName
44+
} else if let index = lists.firstIndex(where: { $0.id == list.id }) {
4345
lists[index] = list
4446
try write(lists)
45-
} else if lists.contains(where: { $0.name == list.name }) {
46-
throw CustomRelayListError.duplicateName
4747
} else {
4848
lists.append(list)
4949
try write(lists)

0 commit comments

Comments
 (0)