Skip to content

Commit

Permalink
Prevent duplicate list names in custom lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson authored and buggmagnet committed Apr 15, 2024
1 parent 8f8bd1d commit c3d575e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ios/MullvadSettings/CustomListRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ public struct CustomListRepository: CustomListRepositoryProtocol {
public func save(list: CustomList) throws {
var lists = fetchAll()

if let index = lists.firstIndex(where: { $0.id == list.id }) {
if let listWithSameName = lists.first(where: { $0.name.caseInsensitiveCompare(list.name) == .orderedSame }),
listWithSameName.id != list.id {
throw CustomRelayListError.duplicateName
} else if let index = lists.firstIndex(where: { $0.id == list.id }) {
lists[index] = list
try write(lists)
} else if lists.contains(where: { $0.name == list.name }) {
throw CustomRelayListError.duplicateName
} else {
lists.append(list)
try write(lists)
Expand Down

0 comments on commit c3d575e

Please sign in to comment.