Skip to content

Commit 0a04d62

Browse files
committed
fix
Signed-off-by: Yuri Shkuro <[email protected]>
1 parent b0e65b3 commit 0a04d62

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

mapstructure.go

+4-9
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,7 @@ func isNil(input interface{}) bool {
448448
return true
449449
}
450450
val := reflect.ValueOf(input)
451-
k := val.Kind()
452-
return (k == reflect.Ptr ||
453-
/*k == reflect.Interface || k == reflect.Map || k == reflect.Slice*/ false) && val.IsNil()
451+
return val.Kind() == reflect.Ptr && val.IsNil()
454452
}
455453

456454
// Decodes an unknown data type into a specific reflection value.
@@ -460,12 +458,9 @@ func (d *Decoder) decode(name string, input interface{}, outVal reflect.Value) e
460458
outputKind = getKind(outVal)
461459
decodeNil = d.config.DecodeNil && d.cachedDecodeHook != nil
462460
)
463-
if input != nil {
464-
// We need to check here if input is a typed nil. Typed nils won't
465-
// match the "input == nil" below so we check that here.
466-
if inputVal.Kind() == reflect.Ptr && inputVal.IsNil() {
467-
input = nil
468-
}
461+
if isNil(input) {
462+
// Typed nils won't match the "input == nil" below, so reset input.
463+
input = nil
469464
}
470465
if input == nil {
471466
// If the data is nil, then we don't set anything, unless ZeroFields is set

mapstructure_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -3089,7 +3089,6 @@ func TestDecoder_DecodeNilOption(t *testing.T) {
30893089
type Transformed struct {
30903090
Message string
30913091
When string
3092-
Boolean *bool //
30933092
}
30943093

30953094
helloHook := func(reflect.Type, reflect.Type, interface{}) (interface{}, error) {

0 commit comments

Comments
 (0)