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

Handle null op, path and from without panicking #62

Merged
merged 1 commit into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (n *lazyNode) equal(o *lazyNode) bool {
}

func (o operation) kind() string {
if obj, ok := o["op"]; ok {
if obj, ok := o["op"]; ok && obj != nil {
var op string

err := json.Unmarshal(*obj, &op)
Expand All @@ -220,7 +220,7 @@ func (o operation) kind() string {
}

func (o operation) path() string {
if obj, ok := o["path"]; ok {
if obj, ok := o["path"]; ok && obj != nil {
var op string

err := json.Unmarshal(*obj, &op)
Expand All @@ -236,7 +236,7 @@ func (o operation) path() string {
}

func (o operation) from() string {
if obj, ok := o["from"]; ok {
if obj, ok := o["from"]; ok && obj != nil{
var op string

err := json.Unmarshal(*obj, &op)
Expand Down
12 changes: 12 additions & 0 deletions patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ var BadCases = []BadCase{
`{ "foo": ["bar"]}`,
`[ {"op": "add", "path": "/foo/2", "value": "bum"}]`,
},
{
`{}`,
`[ {"op":null,"path":""} ]`,
},
{
`{}`,
`[ {"op":"add","path":null} ]`,
},
{
`{}`,
`[ { "op": "copy", "from": null }]`,
},
}

func TestAllCases(t *testing.T) {
Expand Down