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

🐛 fix: Nil pointer dereference with Must Bind binding #3171

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func (b *Bind) Must() *Bind {

// Check Should/Must errors and return it by usage.
func (b *Bind) returnErr(err error) error {
if !b.should {
b.ctx.Status(StatusBadRequest)
return NewError(StatusBadRequest, "Bad request: "+err.Error())
if err == nil || b.should {
ItsMeSamey marked this conversation as resolved.
Show resolved Hide resolved
return err
}

return err
b.ctx.Status(StatusBadRequest)
return NewError(StatusBadRequest, "Bad request: "+err.Error())
ItsMeSamey marked this conversation as resolved.
Show resolved Hide resolved
}

// Struct validation.
Expand Down
9 changes: 9 additions & 0 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@

const helloWorld = "hello world"

// go test -run Test_returnErr -v
func Test_returnErr(t *testing.T) {
app := New()
c := app.AcquireCtx(&fasthttp.RequestCtx{})

err := c.Bind().Must().returnErr(nil)
require.Equal(t, nil, err)

Check failure on line 28 in bind_test.go

View workflow job for this annotation

GitHub Actions / lint

error-nil: use require.NoError (testifylint)
}

// go test -run Test_Bind_Query -v
func Test_Bind_Query(t *testing.T) {
t.Parallel()
Expand Down
Loading