Skip to content

Commit b65b5a4

Browse files
committed
Fix panic on test op
1 parent 6a7ad8a commit b65b5a4

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

patch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ func (p Patch) test(doc *container, op Operation) error {
688688
}
689689

690690
if val == nil {
691-
if op.value().raw == nil {
691+
if op.value() == nil || op.value().raw == nil {
692692
return nil
693693
}
694694
return errors.Wrapf(ErrTestFailed, "testing value %s failed", path)

patch_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ var TestCases = []TestCase{
496496
false,
497497
"/foo",
498498
},
499+
{
500+
`{ "baz": [] }`,
501+
`[ { "op": "test", "path": "/foo"} ]`,
502+
true,
503+
"/foo",
504+
},
499505
}
500506

501507
func TestAllTest(t *testing.T) {

v5/patch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ func (p Patch) test(doc *container, op Operation, options *ApplyOptions) error {
965965
}
966966

967967
if val == nil {
968-
if op.value().raw == nil {
968+
if op.value() == nil || op.value().raw == nil {
969969
return nil
970970
}
971971
return errors.Wrapf(ErrTestFailed, "testing value %s failed", path)

v5/patch_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,13 @@ var Cases = []Case{
571571
}`,
572572
false, true,
573573
},
574+
{
575+
`{"baz": []}`,
576+
`[ { "op": "test", "path": "/foo" } ]`,
577+
`{"baz": []}`,
578+
false,
579+
false,
580+
},
574581
}
575582

576583
type BadCase struct {

0 commit comments

Comments
 (0)