Skip to content

Commit

Permalink
Set urlComponents.percentEncodedHost if os is not linux
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFossAWS committed May 23, 2024
1 parent 3c58f42 commit 8ea7af9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 9 additions & 1 deletion Sources/ClientRuntime/Message/URI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ public final class URIBuilder {
@discardableResult
public func withHost(_ value: String) -> URIBuilder {
if value.isPercentEncoded {
self.urlComponents.percentEncodedHost = value
// URLComponents.percentEncodedHost follows RFC 3986
// and returns a decoded value if it is set with a percent encoded value
// However on Linux platform, it returns a percent encoded value.
// To ensure consistent behaviour, we will decode it ourselves on Linux platform
if currentOS == .linux {
self.urlComponents.host = value.removingPercentEncoding!
} else {
self.urlComponents.percentEncodedHost = value
}
} else {
self.urlComponents.host = value
}
Expand Down
9 changes: 2 additions & 7 deletions Tests/ClientRuntimeTests/MessageTests/URITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,7 @@ class URITests: XCTestCase {
.withPassword("%24008")
.build()

#if os(Linux)
XCTAssertEqual(uri.url?.absoluteString,
"https://dan%21:%24008@%2Bxctest2.com/x%2Dy%2Dz?abc=def&ghi=jkl&mno=pqr&test=1%2B2#fragment%21")
#else
XCTAssertEqual(uri.url?.absoluteString,
"https://dan%21:%24008@+xctest2.com/x%2Dy%2Dz?abc=def&ghi=jkl&mno=pqr&test=1%2B2#fragment%21")
#endif
XCTAssertEqual(uri.url?.absoluteString,
"https://dan%21:%24008@+xctest2.com/x%2Dy%2Dz?abc=def&ghi=jkl&mno=pqr&test=1%2B2#fragment%21")
}
}

0 comments on commit 8ea7af9

Please sign in to comment.