Skip to content

Commit

Permalink
fix(client): Return nil if endpoint is empty string
Browse files Browse the repository at this point in the history
Why:
Passing an empty string as an endpoint to Client when instantiating a
new client might seem like something that should never happen but I
managed to trigger it while parsing some input files to register feeds
in bulk.

What:
Check if the endpoint passed to NewClient is "" and then return
immediately nil.

Arguably, the function should instead be altered to return an error, but
that would change the signature of the function, introducing a backwards
incompatible change and break the API
  • Loading branch information
akosiaris committed Jul 30, 2024
1 parent d048d59 commit b4b1842
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func NewClient(endpoint string, credentials ...string) *Client {
// Trim trailing slashes and /v1 from the endpoint.
endpoint = strings.TrimSuffix(endpoint, "/")
endpoint = strings.TrimSuffix(endpoint, "/v1")
// If we end up with an empty string as an endpoint, it's an user input error
if endpoint == "" {
return nil
}
switch len(credentials) {
case 2:
return &Client{request: &request{endpoint: endpoint, username: credentials[0], password: credentials[1]}}
Expand Down

0 comments on commit b4b1842

Please sign in to comment.