1
0
Fork 0

fix(client): Return nil and error if endpoint is empty string

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 ErrEmptyEndpoint with a
descriptive string
This commit is contained in:
Alexandros Kosiaris 2024-03-29 16:45:32 +02:00 committed by Frédéric Guillot
parent f3a5a3ee14
commit 89ff33ddd0

View file

@ -27,6 +27,7 @@ var (
ErrServerError = errors.New("miniflux: internal server error") ErrServerError = errors.New("miniflux: internal server error")
ErrNotFound = errors.New("miniflux: resource not found") ErrNotFound = errors.New("miniflux: resource not found")
ErrBadRequest = errors.New("miniflux: bad request") ErrBadRequest = errors.New("miniflux: bad request")
ErrEmptyEndpoint = errors.New("miniflux: empty endpoint provided")
) )
type errorResponse struct { type errorResponse struct {
@ -62,6 +63,9 @@ func (r *request) Delete(path string) error {
} }
func (r *request) execute(method, path string, data interface{}) (io.ReadCloser, error) { func (r *request) execute(method, path string, data interface{}) (io.ReadCloser, error) {
if r.endpoint == "" {
return nil, ErrEmptyEndpoint
}
if r.endpoint[len(r.endpoint)-1:] == "/" { if r.endpoint[len(r.endpoint)-1:] == "/" {
r.endpoint = r.endpoint[:len(r.endpoint)-1] r.endpoint = r.endpoint[:len(r.endpoint)-1]
} }