Bug Description
SwaggerUIHandler in pkg/gofr/swagger.go:53 panics with an index out of bounds error when the requested filename has no . (dot) in it.
Root Cause
The code splits the filename on . and directly accesses split[1] without checking the length:
func SwaggerUIHandler(c *Context) (any, error) {
fileName := c.PathParam("name")
if fileName == "" {
fileName = "index.html"
}
data, err := fs.ReadFile("static/" + fileName)
if err != nil {
c.Errorf("Failed to read Swagger UI file %s from embedded file system: %v", fileName, err)
return nil, err
}
split := strings.Split(fileName, ".")
ct := mime.TypeByExtension("." + split[1]) // PANIC: index out of range if no "." in fileName
// ...
}
Bug Description
SwaggerUIHandlerinpkg/gofr/swagger.go:53panics with an index out of bounds error when the requested filename has no.(dot) in it.Root Cause
The code splits the filename on
.and directly accessessplit[1]without checking the length: