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]: BodyParser doesn't parse form values to map #3216

Open
3 tasks done
sujit-baniya opened this issue Nov 24, 2024 · 2 comments
Open
3 tasks done

🐛 [Bug]: BodyParser doesn't parse form values to map #3216

sujit-baniya opened this issue Nov 24, 2024 · 2 comments

Comments

@sujit-baniya
Copy link
Contributor

Bug Description

When trying to parse a form data to map, I'm getting an error schema: interface must be a pointer to struct

https://youtu.be/XnhXTXW8JmM

How to Reproduce

package main

import (
	"bytes"
	"errors"
	"net/url"
	"reflect"
	
	"github.com/gofiber/fiber/v2"
)

func main() {
	app := fiber.New()
	
	app.Post("/", func(ctx *fiber.Ctx) error {
		var data map[string]any
		err := ctx.BodyParser(&data)
		if err != nil {
			return err
		}
		return ctx.JSON(data)
	})
	app.Listen(":8081")
}
curl -X POST http://localhost:8081 \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "method=GET&path=/user/:id&handlerMsg=User Profile"


Expected Behavior

It should have worked with map, struct or slice

Fiber Version

v2.52.5

Code Snippet (optional)

package main

import (
	"bytes"
	"errors"
	"net/url"
	"reflect"
	
	"github.com/gofiber/fiber/v2"
)

func main() {
	app := fiber.New()
	
	app.Post("/", func(ctx *fiber.Ctx) error {
		var data map[string]any
		err := ctx.BodyParser(&data)
		if err != nil {
			return err
		}
		return ctx.JSON(data)
	})
	app.Listen(":8081")
}

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.
@klikpaspor
Copy link

var data map[string]any

Maybe you have change var data map[string]any to var data map[string]interface{}

@sujit-baniya
Copy link
Contributor Author

@klikpaspor It's same for both

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

2 participants