Skip to content

Commit

Permalink
Fixed issue with panic that can occur on calls to CanInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
deelawn committed Nov 10, 2020
1 parent 433831e commit e4611c8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ func (m Matcher) matchesValue(v1, v2 reflect.Value, visited map[visit]bool, dept
return true
}

// For excluding unexported and exported fields, each call to CanInterface needs to be preceded by
// a call to IsValid because calling CanInterface on an invalid valid will panic. If either value is
// invalid then it will be caught after these exclusions in the subsequent IsValid checks.

// Skip comparison if one of these is unexported and we are not comparing unexported
if m.ExcludeUnexported && (!v1.CanInterface() || !v2.CanInterface()) {
if m.ExcludeUnexported && ((v1.IsValid() && !v1.CanInterface()) || (v2.IsValid() && !v2.CanInterface())) {
return true
}

// Skip comparison if one of these is exported and we are not comparing exported values
if m.ExcludeExported && (v1.CanInterface() || v2.CanInterface()) {
if m.ExcludeExported && ((v1.IsValid() && v1.CanInterface()) || (v2.IsValid() && v2.CanInterface())) {
return true
}

Expand Down

0 comments on commit e4611c8

Please sign in to comment.