Skip to content

Commit

Permalink
Merge pull request #317 from DataDog/buranmert/RUMM-894-whitespaced-q…
Browse files Browse the repository at this point in the history
…uery-crash

RUMM-894 URLProvider fixed for illegal chars
  • Loading branch information
ncreated authored Nov 24, 2020
2 parents 51cd4a3 + ac9e6af commit 6a4b76a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Datadog/Core/Upload/DataUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6a4b76a

Please sign in to comment.