Skip to content

Commit

Permalink
fix(client): Return nil and error 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:
In the execute() function, check early if the endpoint is "" and then
return immediately nil and a new error, named ErrWrongEndpoint with a
descriptive string
  • Loading branch information
akosiaris committed Aug 17, 2024
1 parent e98e16e commit da64ee5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
ErrServerError = errors.New("miniflux: internal server error")
ErrNotFound = errors.New("miniflux: resource not found")
ErrBadRequest = errors.New("miniflux: bad request")
ErrWrongEndpoint = errors.New("miniflux: endpoint badly configured")
)

type errorResponse struct {
Expand Down Expand Up @@ -62,6 +63,10 @@ func (r *request) Delete(path string) error {
}

func (r *request) execute(method, path string, data interface{}) (io.ReadCloser, error) {
// If we end up with an empty string as an endpoint, it's an user input error
if r.endpoint == "" {
return nil, ErrWrongEndpoint
}
if r.endpoint[len(r.endpoint)-1:] == "/" {
r.endpoint = r.endpoint[:len(r.endpoint)-1]
}
Expand Down

0 comments on commit da64ee5

Please sign in to comment.