Don't attempt to set unexported struct fields
diff --git a/mapstructure.go b/mapstructure.go index f953a8b..53d632f 100644 --- a/mapstructure.go +++ b/mapstructure.go
@@ -236,6 +236,12 @@ panic("field is not valid") } + // If we can't set the field, then it is unexported or something, + // and we just continue onwards. + if !field.CanSet() { + continue + } + // If the name is empty string, then we're at the root, and we // don't dot-join the fields. if name != "" {
diff --git a/mapstructure_test.go b/mapstructure_test.go index c417762..f131397 100644 --- a/mapstructure_test.go +++ b/mapstructure_test.go
@@ -7,6 +7,7 @@ Vint int Vbool bool Vextra string + vsilent bool } type Map struct { @@ -39,6 +40,7 @@ "vstring": "foo", "vint": 42, "vbool": true, + "vsilent": true, } var result Basic @@ -63,6 +65,10 @@ if result.Vextra != "" { t.Errorf("vextra value should be empty: %#v", result.Vextra) } + + if result.vsilent != false { + t.Error("vsilent should not be set, it is unexported") + } } func TestMap(t *testing.T) {