Clean extra tag contents when determining field name
diff --git a/mapstructure.go b/mapstructure.go
index 253859f..e7c4155 100644
--- a/mapstructure.go
+++ b/mapstructure.go
@@ -382,6 +382,7 @@
fieldName := fieldType.Name
tagValue := fieldType.Tag.Get(d.config.TagName)
+ tagValue = strings.SplitN(tagValue, ",", 2)[0]
if tagValue != "" {
fieldName = tagValue
}
diff --git a/mapstructure_test.go b/mapstructure_test.go
index 5535f8e..5f359c2 100644
--- a/mapstructure_test.go
+++ b/mapstructure_test.go
@@ -49,6 +49,7 @@
}
type Tagged struct {
+ Extra string `mapstructure:"bar,what,what"`
Value string `mapstructure:"foo"`
}
@@ -525,6 +526,7 @@
input := map[string]interface{}{
"foo": "bar",
+ "bar": "value",
}
var result Tagged
@@ -536,6 +538,10 @@
if result.Value != "bar" {
t.Errorf("value should be 'bar', got: %#v", result.Value)
}
+
+ if result.Extra != "value" {
+ t.Errorf("extra should be 'value', got: %#v", result.Extra)
+ }
}
func testSliceInput(t *testing.T, input map[string]interface{}, expected *Slice) {