diff --git a/Sources/ClientRuntime/Networking/Endpoint.swift b/Sources/ClientRuntime/Networking/Endpoint.swift index f51cf8dd5..9dbb65857 100644 --- a/Sources/ClientRuntime/Networking/Endpoint.swift +++ b/Sources/ClientRuntime/Networking/Endpoint.swift @@ -63,10 +63,10 @@ extension Endpoint { public var url: URL? { var components = URLComponents() components.scheme = protocolType?.rawValue - components.host = host + components.host = host.isEmpty ? nil : host // If host is empty, URL is invalid components.percentEncodedPath = path components.percentEncodedQuery = queryItemString - return components.url + return (components.host == nil || components.scheme == nil) ? nil : components.url } var queryItemString: String? { diff --git a/Tests/ClientRuntimeTests/NetworkingTests/HttpRequestTests.swift b/Tests/ClientRuntimeTests/NetworkingTests/HttpRequestTests.swift index 2c07eb4b0..d2f021029 100644 --- a/Tests/ClientRuntimeTests/NetworkingTests/HttpRequestTests.swift +++ b/Tests/ClientRuntimeTests/NetworkingTests/HttpRequestTests.swift @@ -111,7 +111,9 @@ class HttpRequestTests: NetworkingTestUtils { } func testConversionToUrlRequestFailsWithInvalidEndpoint() { - // TODO:: When is the endpoint invalid or endpoint.url nil? - _ = Endpoint(host: "", path: "", protocolType: nil) + // Testing with an invalid endpoint where host is empty, + // path is empty, and protocolType is nil. + let endpoint = Endpoint(host: "", path: "", protocolType: nil) + XCTAssertNil(endpoint.url, "An invalid endpoint should result in a nil URL.") } }