Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Endpoint url should be nil if host or scheme is missing #614

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/ClientRuntime/Networking/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}
Loading