Skip to content

Commit 83e7369

Browse files
fix: handle nil jsonpointer sources (#213)
Co-authored-by: Tristan Cartledge <108070248+TristanSpeakEasy@users.noreply.github.com>
1 parent ec61790 commit 83e7369

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

jsonpointer/jsonpointer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ func getTarget(source any, currentPart navigationPart, stack []navigationPart, c
127127
}
128128

129129
sourceType := reflect.TypeOf(source)
130+
if sourceType == nil {
131+
return nil, nil, ErrNotFound.Wrap(fmt.Errorf("source is nil at %s", currentPath))
132+
}
130133
sourceElemType := sourceType
131134

132135
if sourceType.Kind() == reflect.Ptr {

jsonpointer/jsonpointer_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@ func TestGetTarget_Error(t *testing.T) {
367367
},
368368
wantErr: errors.New("not found -- slice is nil at /0"),
369369
},
370+
{
371+
name: "nil source",
372+
args: args{
373+
source: nil,
374+
pointer: JSONPointer("/key1"),
375+
},
376+
wantErr: errors.New("not found -- source is nil at /key1"),
377+
},
370378
{
371379
name: "nil struct",
372380
args: args{

0 commit comments

Comments
 (0)