Skip to content

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

@ecoderat

Description

@ecoderat

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions