From 255f3416d41689d7b3038bf8c3abbed5b1e20e65 Mon Sep 17 00:00:00 2001 From: Mert Buran Date: Fri, 20 Nov 2020 23:14:41 +0100 Subject: [PATCH 1/2] RUMM-894 URLProvider fixed for illegal chars Example case: service name with whitespace crashes in RUM --- Sources/Datadog/Core/Upload/DataUploader.swift | 2 +- .../Datadog/Core/Upload/DataUploaderTests.swift | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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..cf19a45c64 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 testIllegalCharactersInQueryItemsDontCrash() 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 { From ac9e6af56938dc97819fc5fdf6445db716f66714 Mon Sep 17 00:00:00 2001 From: Maciek Grzybowski Date: Mon, 23 Nov 2020 10:33:45 +0100 Subject: [PATCH 2/2] RUMM-894 Improve test name --- Tests/DatadogTests/Datadog/Core/Upload/DataUploaderTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/DatadogTests/Datadog/Core/Upload/DataUploaderTests.swift b/Tests/DatadogTests/Datadog/Core/Upload/DataUploaderTests.swift index cf19a45c64..b27fdc5104 100644 --- a/Tests/DatadogTests/Datadog/Core/Upload/DataUploaderTests.swift +++ b/Tests/DatadogTests/Datadog/Core/Upload/DataUploaderTests.swift @@ -47,7 +47,7 @@ class DataUploadURLProviderTests: XCTestCase { XCTAssertEqual(urlProvider.url, URL(string: "https://api.example.com/v1/endpoint/abc?ddsource=ios&batch_time=1576404009999")) } - func testIllegalCharactersInQueryItemsDontCrash() throws { + func testItEscapesWhitespacesInQueryItems() throws { let urlProvider = UploadURLProvider( urlWithClientToken: URL(string: "https://api.example.com/v1/endpoint/abc")!, queryItemProviders: [.ddtags(tags: ["some string with whitespace"])]