File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed
Sources/ClientRuntime/Networking
Tests/ClientRuntimeTests/NetworkingTests Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff 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 ? {
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments