fiber
fiber copied to clipboard
🐛 [Bug]: Incorrect Parsing of Slice by `QueryParser()` with Embedded Structs
Bug Description
When the "Products" field is within the "Person" struct, the QueryParser() correctly parses it as a slice. However, when I separate the "Products" field into another struct and embed it, the QueryParser() incorrectly parses it as a single string instead of a slice.
How to Reproduce
package main
import (
"log"
"github.com/gofiber/fiber/v2"
)
type Person struct {
Name string `query:"name"`
Pass string `query:"pass"`
A
}
type A struct {
Products []string `query:"products"`
}
func main() {
app := fiber.New(fiber.Config{
EnableSplittingOnParsers: true,
})
app.Get("/", func(c *fiber.Ctx) error {
p := new(Person)
if err := c.QueryParser(p); err != nil {
return err
}
log.Println(p.Name)
log.Println(p.Pass)
log.Println(p.Products)
return c.JSON(p)
})
app.Listen(":3000")
}
$ curl "http://localhost:3000/?name=john&pass=doe&products=shoe,hat" | jq
{
"Name": "john",
"Pass": "doe",
"Products": [
"shoe,hat"
]
}
Expected Behavior
$ curl "http://localhost:3000/?name=john&pass=doe&products=shoe,hat" | jq
{
"Name": "john",
"Pass": "doe",
"Products": [
"shoe",
"hat"
]
}
Fiber Version
v2.49.2
Code Snippet (optional)
No response
Checklist:
- [X] I agree to follow Fiber's Code of Conduct.
- [X] I have checked for existing issues that describe my problem prior to opening this one.
- [X] I understand that improperly formatted bug reports may be closed without explanation.
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord
We will look into it
how do i reproduce the app. *I am a beginner