AddStaticFiles with a trailing slash in the endpoint registers a silently dead route
Description
App.AddStaticFiles("static/", dir) registers routes that no request can ever match, and reports success. Every URL under the endpoint 404s.
Raised by @aryanmehrotra during review of #3820 as pre-existing and out of that PR's scope — #3820 rewrites pkg/gofr/http/router.go, while this lives in pkg/gofr/gofr.go.
Steps to reproduce
app := gofr.New()
app.AddStaticFiles("static/", "./static")
app.Run()GET /static -> 404
GET /static/ -> 404
GET /static/index.html -> 404The registration log claims the endpoint is up.
Cause
gofr.go:417 normalizes the endpoint with strings.TrimPrefix(endpoint, "/"), which removes a leading slash only. A trailing one survives, so the router is handed "/static/" and registers:
Path("/static/")PathPrefix("/static//")
Router.ServeHTTP normalizes incoming paths with path.Clean, which strips the trailing slash and collapses the double one, so neither pattern can be matched by a request that has been through it.
Expected
AddStaticFiles("static/", dir) behaves the same as AddStaticFiles("static", dir) and AddStaticFiles("/static", dir) — or, if a trailing slash is to be rejected, it is logged and not silently registered.
Suggested fix
strings.Trim(endpoint, "/") in place of TrimPrefix, with a test covering the endpoint forms a caller can pass — static, /static, static/, /static/.
Version
Reproduces on development (1d238069) and unchanged by #3820.
Source: gofr-dev/gofr