Skip to content

Commit

Permalink
Merge pull request #158 from erickertz/master
Browse files Browse the repository at this point in the history
Fix panic on test op
  • Loading branch information
evanphx committed Sep 11, 2023
2 parents e8e8fb5 + b65b5a4 commit dc808d1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func (p Patch) test(doc *container, op Operation) error {
}

if val == nil {
if op.value().raw == nil {
if op.value() == nil || op.value().raw == nil {
return nil
}
return errors.Wrapf(ErrTestFailed, "testing value %s failed", path)
Expand Down
6 changes: 6 additions & 0 deletions patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@ var TestCases = []TestCase{
false,
"/foo",
},
{
`{ "baz": [] }`,
`[ { "op": "test", "path": "/foo"} ]`,
true,
"/foo",
},
}

func TestAllTest(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion v5/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ func (p Patch) test(doc *container, op Operation, options *ApplyOptions) error {
}

if val == nil {
if op.value().raw == nil {
if op.value() == nil || op.value().raw == nil {
return nil
}
return errors.Wrapf(ErrTestFailed, "testing value %s failed", path)
Expand Down
7 changes: 7 additions & 0 deletions v5/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,13 @@ var Cases = []Case{
}`,
false, true,
},
{
`{"baz": []}`,
`[ { "op": "test", "path": "/foo" } ]`,
`{"baz": []}`,
false,
false,
},
}

type BadCase struct {
Expand Down

0 comments on commit dc808d1

Please sign in to comment.