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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 [Bug]: Incorrect Parsing of Slice by QueryParser() with Embedded Structs #2859

Open
3 tasks done
ecoderat opened this issue Feb 14, 2024 · 3 comments
Open
3 tasks done

Comments

@ecoderat
Copy link

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:

  • 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.
Copy link

welcome bot commented Feb 14, 2024

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

@ReneWerner87
Copy link
Member

We will look into it

@shahkashish
Copy link

how do i reproduce the app.
*I am a beginner

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

No branches or pull requests

3 participants