Skip to content

Commit

Permalink
Merge pull request #4 from m-mizutani/fix/clone-nil
Browse files Browse the repository at this point in the history
Fix nil handling
  • Loading branch information
m-mizutani committed Jul 11, 2023
2 parents 8d2aa33 + a2669dd commit 9efb054
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func TestClone(t *testing.T) {
gt.V(t, v).Equal(masq.DefaultRedactMessage + " is " + masq.DefaultRedactMessage)
})

t.Run("nil", func(t *testing.T) {
gt.V(t, c.Redact(nil)).Nil()
})

t.Run("struct", func(t *testing.T) {
type testData struct {
ID int
Expand Down
3 changes: 3 additions & 0 deletions masq.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func newMasq(options ...Option) *masq {
}

func (x *masq) redact(k string, v any) any {
if v == nil {
return nil
}
copied := x.clone(k, reflect.ValueOf(v), "")
return copied.Interface()
}
Expand Down

0 comments on commit 9efb054

Please sign in to comment.