You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want to do specific request with brackets so will throw a panic
How to Reproduce
package main
import (
"github.com/gofiber/fiber/v2""log"
)
funcmain() {
// Initialize a new Fiber appapp:=fiber.New()
// Define a route for the GET method on the root path '/'app.Get("/", func(ctx*fiber.Ctx) error {
varuserUsererr:=ctx.QueryParser(&user)
iferr!=nil {
returnctx.Status(400).SendString("Invalid user data")
}
returnctx.SendString("Hello, World!")
})
// Start the server on port 3000log.Fatal(app.Listen(":3000"))
}
typeUserstruct {
IDint`json:"id"`Namestring`json:"name"`
}
curl 'http://localhost:3000/?data[=name'
GOROOT=/opt/homebrew/Cellar/go/1.23.0/libexec #gosetup
GOPATH=/Users/ariel.pineiro/go #gosetup
/opt/homebrew/Cellar/go/1.23.0/libexec/bin/go build -o /Users/ariel.pineiro/Library/Caches/JetBrains/GoLand2024.2/tmp/GoLand/___go_build_issue issue #gosetup
/Users/ariel.pineiro/Library/Caches/JetBrains/GoLand2024.2/tmp/GoLand/___go_build_issue
┌───────────────────────────────────────────────────┐
│ Fiber v2.52.5 │
│ http://127.0.0.1:3000 │
│ (bound on host 0.0.0.0 and port 3000) │
│ │
│ Handlers ............. 2 Processes ........... 1 │
│ Prefork ....... Disabled PID ............. 43705 │
└───────────────────────────────────────────────────┘
panic: runtime error: index out of range [5] with length 5
goroutine 20 [running]:
github.com/gofiber/fiber/v2.parseParamSquareBrackets({0x140000b2308, 0x5})
/Users/ariel.pineiro/go/pkg/mod/github.com/gofiber/fiber/[email protected]/ctx.go:1311 +0x264
github.com/gofiber/fiber/v2.(*Ctx).QueryParser.func1({0x140000b2308?, 0x4?, 0x1400016d8b8?}, {0x140000b2330, 0x4, 0x8})
/Users/ariel.pineiro/go/pkg/mod/github.com/gofiber/fiber/[email protected]/ctx.go:1284 +0xd4
github.com/valyala/fasthttp.visitArgs({0x140000b6070, 0x1, 0x1400016d998?}, 0x1400016d948)
/Users/ariel.pineiro/go/pkg/mod/github.com/valyala/[email protected]/args.go:359 +0x68
github.com/valyala/fasthttp.(*Args).VisitAll(...)
/Users/ariel.pineiro/go/pkg/mod/github.com/valyala/[email protected]/args.go:74
github.com/gofiber/fiber/v2.(*Ctx).QueryParser(0x140000c8000, {0x1031c4ca0?, 0x140000ca240})
/Users/ariel.pineiro/go/pkg/mod/github.com/gofiber/fiber/[email protected]/ctx.go:1275 +0xdc
main.main.func1(0x140000c8000)
/Users/ariel.pineiro/projects/iskaypetcom/issue/main.go:15 +0x40
github.com/gofiber/fiber/v2.(*App).next(0x1400015ca00, 0x140000c8000)
/Users/ariel.pineiro/go/pkg/mod/github.com/gofiber/fiber/[email protected]/router.go:145 +0x188
github.com/gofiber/fiber/v2.(*App).handler(0x1400015ca00, 0x1030ef048?)
/Users/ariel.pineiro/go/pkg/mod/github.com/gofiber/fiber/[email protected]/router.go:172 +0x74
github.com/valyala/fasthttp.(*Server).serveConn(0x14000190000, {0x10322b608?, 0x1400009e000})
/Users/ariel.pineiro/go/pkg/mod/github.com/valyala/[email protected]/server.go:2359 +0xdd0
github.com/valyala/fasthttp.(*workerPool).workerFunc(0x1400011a820, 0x140000a2020)
/Users/ariel.pineiro/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:224 +0x70
github.com/valyala/fasthttp.(*workerPool).getCh.func1()
/Users/ariel.pineiro/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:196 +0x38
created by github.com/valyala/fasthttp.(*workerPool).getCh in goroutine 1
/Users/ariel.pineiro/go/pkg/mod/github.com/valyala/[email protected]/workerpool.go:195 +0x208
Process finished with the exit code 2
Expected Behavior
err == nil
Fiber Version
v2.52.5
Code Snippet (optional)
package main
import (
"github.com/gofiber/fiber/v2""log"
)
funcmain() {
// Initialize a new Fiber appapp:=fiber.New()
// Define a route for the GET method on the root path '/'app.Get("/", func(ctx*fiber.Ctx) error {
varuserUsererr:=ctx.QueryParser(&user)
iferr!=nil {
returnctx.Status(400).SendString("Invalid user data")
}
returnctx.SendString("Hello, World!")
})
// Start the server on port 3000log.Fatal(app.Listen(":3000"))
}
typeUserstruct {
IDint`json:"id"`Namestring`json:"name"`
}
@ReneWerner87
Have raised a PR with the probable fix. It is now keeping the track of open and close brackets. In case of mismatch, it returns an error.
Bug Description
If you want to do specific request with brackets so will throw a panic
How to Reproduce
Expected Behavior
err == nil
Fiber Version
v2.52.5
Code Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: