diff --git a/Sources/Datadog/Core/Upload/DataUploader.swift b/Sources/Datadog/Core/Upload/DataUploader.swift index 68fd4a9c51..97b6386877 100644 --- a/Sources/Datadog/Core/Upload/DataUploader.swift +++ b/Sources/Datadog/Core/Upload/DataUploader.swift @@ -41,7 +41,7 @@ internal class UploadURLProvider { var url: URL { var urlComponents = URLComponents(url: urlWithClientToken, resolvingAgainstBaseURL: false) - urlComponents?.percentEncodedQueryItems = queryItemProviders.map { $0.value() } + urlComponents?.queryItems = queryItemProviders.map { $0.value() } guard let url = urlComponents?.url else { userLogger.error("🔥 Failed to create URL from \(urlWithClientToken) with \(queryItemProviders)") diff --git a/Tests/DatadogTests/Datadog/Core/Upload/DataUploaderTests.swift b/Tests/DatadogTests/Datadog/Core/Upload/DataUploaderTests.swift index 753639549d..b27fdc5104 100644 --- a/Tests/DatadogTests/Datadog/Core/Upload/DataUploaderTests.swift +++ b/Tests/DatadogTests/Datadog/Core/Upload/DataUploaderTests.swift @@ -46,6 +46,15 @@ class DataUploadURLProviderTests: XCTestCase { dateProvider.advance(bySeconds: 9.999) XCTAssertEqual(urlProvider.url, URL(string: "https://api.example.com/v1/endpoint/abc?ddsource=ios&batch_time=1576404009999")) } + + func testItEscapesWhitespacesInQueryItems() throws { + let urlProvider = UploadURLProvider( + urlWithClientToken: URL(string: "https://api.example.com/v1/endpoint/abc")!, + queryItemProviders: [.ddtags(tags: ["some string with whitespace"])] + ) + + XCTAssertEqual(urlProvider.url, URL(string: "https://api.example.com/v1/endpoint/abc?ddtags=some%20string%20with%20whitespace")) + } } class DataUploaderTests: XCTestCase {