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

Prevent panic caused by null value in JSON #51

Merged

Conversation

Projects
None yet
3 participants
@RexSkz
Copy link
Contributor

commented Dec 28, 2018

If the request body is a JSON like {"test":null}, govalidator will panic when executing traverseMap.

var m = make(map[string]interface{})
json.Unmarshal([]byte(`{"test":null}`), &m)

Since m["test"] is nil, reflect.TypeOf(v) will panic. This PR fixes the bug by dropping null values in json.

fix(roller): Drop null values in json
If the request body is a JSON like `{"test":null}`, govalidator will panic when executing `traverseMap`.

```go
var m = make(map[string]interface{})
json.Unmarshal([]byte(`{"test":null}`), &m)
```

Since `m["test"]` is `nil`, `reflect.TypeOf(v)` will panic. This PR fixes the bug by dropping null values in json.
@coveralls

This comment has been minimized.

Copy link

commented Dec 28, 2018

Coverage Status

Coverage increased (+0.09%) to 88.919% when pulling 2295389 on RexSkz:rex/prevent-panic-caused-by-null-value into ee7f63f on thedevsaddam:dev.

@thedevsaddam thedevsaddam merged commit 8625cae into thedevsaddam:dev Dec 28, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.09%) to 88.919%
Details

@RexSkz RexSkz deleted the RexSkz:rex/prevent-panic-caused-by-null-value branch Dec 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.