Skip to content

Commit

Permalink
Merge pull request #22 from idrarig/private-map-fix
Browse files Browse the repository at this point in the history
Do not panic on private map properties
  • Loading branch information
darccio committed Feb 16, 2016
2 parents b6f0e7f + ad8026b commit 3e95a51
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions merge.go
Expand Up @@ -53,6 +53,9 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, ov
}
fallthrough
default:
if !srcElement.CanInterface() {
continue
}
switch reflect.TypeOf(srcElement.Interface()).Kind() {
case reflect.Struct:
fallthrough
Expand Down
26 changes: 25 additions & 1 deletion mergo_test.go
Expand Up @@ -6,11 +6,12 @@
package mergo

import (
"gopkg.in/yaml.v1"
"io/ioutil"
"reflect"
"testing"
"time"

"gopkg.in/yaml.v1"
)

type simpleTest struct {
Expand Down Expand Up @@ -499,3 +500,26 @@ func loadYAML(path string) (m map[string]interface{}) {
_ = yaml.Unmarshal(raw, &m)
return
}

type structWithMap struct {
m map[string]structWithUnexportedProperty
}

type structWithUnexportedProperty struct {
s string
}

func TestUnexportedProperty(t *testing.T) {
a := structWithMap{map[string]structWithUnexportedProperty{
"key": structWithUnexportedProperty{"hello"},
}}
b := structWithMap{map[string]structWithUnexportedProperty{
"key": structWithUnexportedProperty{"hi"},
}}
defer func() {
if r := recover(); r != nil {
t.Errorf("Should not have panicked")
}
}()
Merge(&a, b)
}

0 comments on commit 3e95a51

Please sign in to comment.