diff --git a/Sources/Common/Extensions/StringExtensions.swift b/Sources/Common/Extensions/StringExtensions.swift index a0b488e31..74409dc14 100644 --- a/Sources/Common/Extensions/StringExtensions.swift +++ b/Sources/Common/Extensions/StringExtensions.swift @@ -31,11 +31,6 @@ public extension String { String((0 ..< length).map { _ in abcLetters.randomElement()! }) } - static func randomStringWithSpecialCharacters(length: Int = 20) -> String { - let characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~:/?#[]@!$&'()*+,;=%" - return String((0 ..< length).map { _ in characters.randomElement()! }) - } - /** Checks if the string matches the regex pattern. diff --git a/Tests/Common/Service/HttpEndpointTest.swift b/Tests/Common/Service/HttpEndpointTest.swift index 424098fa5..870badf4d 100644 --- a/Tests/Common/Service/HttpEndpointTest.swift +++ b/Tests/Common/Service/HttpEndpointTest.swift @@ -45,12 +45,14 @@ class HttpEndpointTest: UnitTest { XCTAssertEqual(actual, expected) } - func test_getUrlString_givenRandomPathNeedsEncoding_expectEncodedPath() { - let identifierWithSpecialChar = String.randomStringWithSpecialCharacters() + func test_getUrlString_givenPathWithSpecialCharacters_expectEncodedPath() { + let identifierWithSpecialChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~:/?#[]@!$&'()*+,;=%" let endpoint = CIOApiEndpoint.identifyCustomer(identifier: identifierWithSpecialChar) - let expectedIdentifier = identifierWithSpecialChar.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? identifierWithSpecialChar - let expected = "https://customer.io/api/v1/customers/\(expectedIdentifier)" + let rawPath = "/api/v1/customers/\(identifierWithSpecialChar)" + let expectedPath = rawPath.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? rawPath + + let expected = "https://customer.io\(expectedPath)" setHttpBaseUrls(trackingApi: "https://customer.io")