Skip to content

Commit 96b95c1

Browse files
authored
fix: Endpoint url should be nil if host or scheme is missing (#614)
1 parent 6037a81 commit 96b95c1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Sources/ClientRuntime/Networking/Endpoint.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ extension Endpoint {
6363
public var url: URL? {
6464
var components = URLComponents()
6565
components.scheme = protocolType?.rawValue
66-
components.host = host
66+
components.host = host.isEmpty ? nil : host // If host is empty, URL is invalid
6767
components.percentEncodedPath = path
6868
components.percentEncodedQuery = queryItemString
69-
return components.url
69+
return (components.host == nil || components.scheme == nil) ? nil : components.url
7070
}
7171

7272
var queryItemString: String? {

Tests/ClientRuntimeTests/NetworkingTests/HttpRequestTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ class HttpRequestTests: NetworkingTestUtils {
111111
}
112112

113113
func testConversionToUrlRequestFailsWithInvalidEndpoint() {
114-
// TODO:: When is the endpoint invalid or endpoint.url nil?
115-
_ = Endpoint(host: "", path: "", protocolType: nil)
114+
// Testing with an invalid endpoint where host is empty,
115+
// path is empty, and protocolType is nil.
116+
let endpoint = Endpoint(host: "", path: "", protocolType: nil)
117+
XCTAssertNil(endpoint.url, "An invalid endpoint should result in a nil URL.")
116118
}
117119
}

0 commit comments

Comments
 (0)