diff --git a/jsonpointer/jsonpointer.go b/jsonpointer/jsonpointer.go index 042ee0b..3abb7d0 100644 --- a/jsonpointer/jsonpointer.go +++ b/jsonpointer/jsonpointer.go @@ -127,6 +127,9 @@ func getTarget(source any, currentPart navigationPart, stack []navigationPart, c } sourceType := reflect.TypeOf(source) + if sourceType == nil { + return nil, nil, ErrNotFound.Wrap(fmt.Errorf("source is nil at %s", currentPath)) + } sourceElemType := sourceType if sourceType.Kind() == reflect.Ptr { diff --git a/jsonpointer/jsonpointer_test.go b/jsonpointer/jsonpointer_test.go index e49fd04..5852e2d 100644 --- a/jsonpointer/jsonpointer_test.go +++ b/jsonpointer/jsonpointer_test.go @@ -367,6 +367,14 @@ func TestGetTarget_Error(t *testing.T) { }, wantErr: errors.New("not found -- slice is nil at /0"), }, + { + name: "nil source", + args: args{ + source: nil, + pointer: JSONPointer("/key1"), + }, + wantErr: errors.New("not found -- source is nil at /key1"), + }, { name: "nil struct", args: args{