You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- if cfg.ContextKey == "" {+ if cfg.ContextKey == nil || cfg.ContextKey == "" {
cfg.ContextKey = ConfigDefault.ContextKey
}
The fix checks if cfg.ContextKey is either nil or an empty string before assigning the default value ConfigDefault.ContextKey. This ensures that the ContextKey is not missing or empty.
How to Reproduce
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/requestid"
"github.com/gofiber/fiber/v2/utils"
)
import "log"
func main() {
app := fiber.New()
// Steps to reproduce
app.Use(requestid.New(requestid.Config{
// ContextKey is currently nil
Generator: utils.UUID,
}))
log.Fatal(app.Listen(":3000"))
}
ContextKey is a string i assume and a string can never be nil in Go unless its an interface{}.
So strings in Go can never be nil, but only be a zero value to their concrete type which is an empty string.
Conclusion:
Invalid bug mark? plus invalid condition check; unnecessary or operator (slightly more usage on memory (also not fitting innovation of fiber and fasthttp)
Bug Description
This is my fix:
#2731
The fix checks if
cfg.ContextKey
is eithernil
or an empty string before assigning the default valueConfigDefault.ContextKey
. This ensures that theContextKey
is not missing or empty.How to Reproduce
Expected Behavior
...
Fiber Version
v2.51.0
Code Snippet (optional)
No response
Checklist:
The text was updated successfully, but these errors were encountered: