Skip to content

Commit

Permalink
Merge pull request #64 from r3labs/patch-nil-pointer
Browse files Browse the repository at this point in the history
assign an empty type when patch value is nil
  • Loading branch information
purehyperbole authored Jul 12, 2021
2 parents 04a5761 + 5f0fcde commit 9d1db3b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Diff [![PkgGoDev](https://pkg.go.dev/badge/github.com/r3labs/diff)](https://pkg.go.dev/github.com/r3labs/diff) [![Go Report Card](https://goreportcard.com/badge/github.com/r3labs/diff)](https://goreportcard.com/report/github.com/r3labs/diff) [![Build Status](https://travis-ci.org/r3labs/diff.svg?branch=master)](https://travis-ci.org/r3labs/diff)
# Diff [![PkgGoDev](https://pkg.go.dev/badge/github.com/r3labs/diff)](https://pkg.go.dev/github.com/r3labs/diff) [![Go Report Card](https://goreportcard.com/badge/github.com/r3labs/diff)](https://goreportcard.com/report/github.com/r3labs/diff) [![Build Status](https://travis-ci.com/r3labs/diff.svg?branch=master)](https://travis-ci.com/r3labs/diff)

A library for diffing golang structures and values.

Expand Down
7 changes: 6 additions & 1 deletion change_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ func (c *ChangeValue) Set(value reflect.Value, convertCompatibleTypes bool) {
}
c.target.Set(value.Convert(c.target.Type()))
} else {
c.target.Set(value)
if value.IsValid() {
c.target.Set(value)
} else {
t := c.target.Elem()
t.Set(reflect.Zero(t.Type()))
}
}
c.SetFlag(FlagApplied)
}
Expand Down

0 comments on commit 9d1db3b

Please sign in to comment.