Skip to content
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
3 changes: 3 additions & 0 deletions components/scrubber/scrubber.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ func (s *scrubberImpl) deepCopyStruct(fieldName string, src reflect.Value, scrub
return dst

case reflect.Interface:
if src.IsNil() {
return src
}
dst := reflect.New(src.Elem().Type())
copied := s.deepCopyStruct(fieldName, src.Elem(), scrubTag, skipScrub)
dst.Elem().Set(copied)
Expand Down
36 changes: 36 additions & 0 deletions components/scrubber/scrubber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,42 @@ func TestDeepCopyStruct(t *testing.T) {
},
CmpOpts: []cmp.Option{cmpopts.IgnoreUnexported(UnexportedStructToTest{})},
},
{
Name: "nil interface",
Struct: &struct {
Hashed string `scrub:"hash"`
NilInterface interface{}
}{
Hashed: "foo",
},
Expectation: Expectation{
Result: &struct {
Hashed string `scrub:"hash"`
NilInterface interface{}
}{
Hashed: "[redacted:md5:acbd18db4cc2f85cedef654fccc4a4d8]",
NilInterface: nil,
},
},
},
{
Name: "nil point interface",
Struct: &struct {
Hashed string `scrub:"hash"`
NilInterface *string
}{
Hashed: "foo",
},
Expectation: Expectation{
Result: &struct {
Hashed string `scrub:"hash"`
NilInterface *string
}{
Hashed: "[redacted:md5:acbd18db4cc2f85cedef654fccc4a4d8]",
NilInterface: nil,
},
},
},
}

for _, test := range tests {
Expand Down
Loading