Skip to content

Commit

Permalink
Remove array mutibility
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-el committed Sep 26, 2023
1 parent 9c079bc commit f1f1227
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions Sources/Core/Tracker/Tracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,9 @@ class Tracker: NSObject {
var components = URLComponents(url: url, resolvingAgainstBaseURL: false)
let spQueryParam = URLQueryItem(name: "_sp", value: spParameters)

if let index = components?.queryItems?.firstIndex(where: { $0.name == "_sp" }) {
// Replace the old query item with the new one
components?.queryItems?[index] = spQueryParam
} else {
let queryItems = components?.queryItems ?? []
components?.queryItems = queryItems + [spQueryParam]
}
// Modification requires exclusive access, we must make a copy
var queryItems = components?.queryItems
components?.queryItems = (queryItems?.filter { $0.name != "_sp" } ?? []) + [spQueryParam]

return components?.url
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestLinkDecorator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class TestLinkDecorator: XCTestCase {

let result = tracker.decorateLink(link, extendedParameters: CrossDeviceParameterConfiguration(sessionId: false, sourceId: false))!

matches(for: "https://example.com?a=a&_sp=\(tracker.session!.userId!).\(epoch)&b=b", in: result.absoluteString)
matches(for: "https://example.com?a=a&b=b&_sp=\(tracker.session!.userId!).\(epoch)&b=b", in: result.absoluteString)
}

func testMissingFields() {
Expand Down

0 comments on commit f1f1227

Please sign in to comment.