Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [Bug]: Missing ContextKey in requestid middleware configuration #2732

Closed
3 tasks done
gopkg-dev opened this issue Nov 18, 2023 · 2 comments · Fixed by #2742
Closed
3 tasks done

🐛 [Bug]: Missing ContextKey in requestid middleware configuration #2732

gopkg-dev opened this issue Nov 18, 2023 · 2 comments · Fixed by #2742

Comments

@gopkg-dev
Copy link

gopkg-dev commented Nov 18, 2023

Bug Description

This is my fix:

#2731

-	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"))
}

Expected Behavior

...

Fiber Version

v2.51.0

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.
@Z3NTL3
Copy link
Contributor

Z3NTL3 commented Nov 22, 2023

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)

@ReneWerner87 correct if its wrong, thnx ^^

@ReneWerner87
Copy link
Member

@Z3NTL3 pls check #2731 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants