-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Look through interfaces and pointers when determining emptiness
When dealing with map[string]interface{}, the common case for loading arbitrary data from yaml/json, empty strings are not overwritten because they appear as a non-empty interface containing an empty string. This change causes non-nil interfaces to be examined for emptiness.
- Loading branch information
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package mergo | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
type mapInterface map[string]interface{} | ||
|
||
func TestMergeMapsEmptyString(t *testing.T) { | ||
a := mapInterface{"s": ""} | ||
b := mapInterface{"s": "foo"} | ||
if err := Merge(&a, b); err != nil { | ||
t.Fatal(err) | ||
} | ||
if a["s"] != "foo" { | ||
t.Fatalf("b not merged in properly: a.s.Value(%s) != expected(%s)", a["s"], "foo") | ||
} | ||
} |