diff --git a/ctx.go b/ctx.go index ea7d5bff..2f9394bd 100644 --- a/ctx.go +++ b/ctx.go @@ -1081,17 +1081,17 @@ func (c *Ctx) QueryInt(key string, defaultValue ...int) int { // Get /?name=alex&want_pizza=false&id= // QueryBool("want_pizza") == false // QueryBool("want_pizza", true) == false -// QueryBool("alex") == true -// QueryBool("alex", false) == false -// QueryBool("id") == true -// QueryBool("id", false) == false +// QueryBool("name") == false +// QueryBool("name", true) == true +// QueryBool("id") == false +// QueryBool("id", true) == true func (c *Ctx) QueryBool(key string, defaultValue ...bool) bool { value, err := strconv.ParseBool(c.app.getString(c.fasthttp.QueryArgs().Peek(key))) if err != nil { if len(defaultValue) > 0 { return defaultValue[0] } - return true + return false } return value } diff --git a/ctx_test.go b/ctx_test.go index 2a67302f..b3192a8f 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -2179,10 +2179,10 @@ func Test_Ctx_QueryBool(t *testing.T) { utils.AssertEqual(t, false, c.QueryBool("want_pizza")) utils.AssertEqual(t, false, c.QueryBool("want_pizza", true)) - utils.AssertEqual(t, true, c.QueryBool("name")) - utils.AssertEqual(t, false, c.QueryBool("name", false)) - utils.AssertEqual(t, true, c.QueryBool("id")) - utils.AssertEqual(t, false, c.QueryBool("id", false)) + utils.AssertEqual(t, false, c.QueryBool("name")) + utils.AssertEqual(t, true, c.QueryBool("name", true)) + utils.AssertEqual(t, false, c.QueryBool("id")) + utils.AssertEqual(t, true, c.QueryBool("id", true)) } func Test_Ctx_QueryFloat(t *testing.T) { diff --git a/docs/api/ctx.md b/docs/api/ctx.md index 52a2d3c6..f102ee37 100644 --- a/docs/api/ctx.md +++ b/docs/api/ctx.md @@ -1088,8 +1088,8 @@ This property is an object containing a property for each query boolean paramete :::caution -Please note if that parameter is not in the request, true will be returned. -If the parameter is not a boolean, it is still tried to be converted and usually returned as true. +Please note if that parameter is not in the request, false will be returned. +If the parameter is not a boolean, it is still tried to be converted and usually returned as false. ::: ```go title="Signature" @@ -1100,12 +1100,12 @@ func (c *Ctx) QueryBool(key string, defaultValue ...bool) bool // GET http://example.com/?name=alex&want_pizza=false&id= app.Get("/", func(c *fiber.Ctx) error { - c.QueryBool("want_pizza") // false + c.QueryBool("want_pizza") // false c.QueryBool("want_pizza", true) // false - c.QueryBool("alex") // true - c.QueryBool("alex", false) // false - c.QueryBool("id") // true - c.QueryBool("id", false) // false + c.QueryBool("name") // false + c.QueryBool("name", true) // true + c.QueryBool("id") // false + c.QueryBool("id", true) // true // ... })