Skip to content

Commit

Permalink
Make custom list names case sensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson committed Apr 29, 2024
1 parent 0454d16 commit cfb2dcb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ios/MullvadSettings/CustomListRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public struct CustomListRepository: CustomListRepositoryProtocol {
public func save(list: CustomList) throws {
var lists = fetchAll()

if let listWithSameName = lists.first(where: { $0.name.caseInsensitiveCompare(list.name) == .orderedSame }),
if let listWithSameName = lists.first(where: { $0.name.compare(list.name) == .orderedSame }),
listWithSameName.id != list.id {
throw CustomRelayListError.duplicateName
} else if let index = lists.firstIndex(where: { $0.id == list.id }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CustomListLocationNodeBuilder {
var customListLocationNode: CustomListLocationNode {
let listNode = CustomListLocationNode(
name: customList.name,
code: customList.name.lowercased(),
code: customList.name,
locations: customList.locations,
isActive: !customList.locations.isEmpty,
customList: customList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ class CustomListRepositoryTests: XCTestCase {

func testFailedAddingDuplicateCustomList() throws {
let item1 = CustomList(name: "Netflix", locations: [])
let item2 = CustomList(name: "Netflix", locations: [])
let item2 = CustomList(name: "netflix", locations: [])
let item3 = CustomList(name: "Netflix", locations: [])

try XCTAssertNoThrow(repository.save(list: item1))
try XCTAssertNoThrow(repository.save(list: item2))

XCTAssertThrowsError(try repository.save(list: item2)) { error in
XCTAssertThrowsError(try repository.save(list: item3)) { error in
XCTAssertEqual(error as? CustomRelayListError, CustomRelayListError.duplicateName)
}
}
Expand Down

0 comments on commit cfb2dcb

Please sign in to comment.