From 9a962379e65aa18f76dcb18117d432b84a11083b Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 24 Jun 2024 18:14:40 +0200 Subject: [PATCH] fix: do not allow overwriting the mapstructure output Signed-off-by: Mark Sagi-Kazar --- viper.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/viper.go b/viper.go index 6ec598c48..143ec9dc5 100644 --- a/viper.go +++ b/viper.go @@ -945,7 +945,6 @@ func (v *Viper) decodeStructKeys(input any, opts ...DecoderConfigOption) ([]stri func defaultDecoderConfig(output any, opts ...DecoderConfigOption) *mapstructure.DecoderConfig { c := &mapstructure.DecoderConfig{ Metadata: nil, - Result: output, WeaklyTypedInput: true, DecodeHook: mapstructure.ComposeDecodeHookFunc( mapstructure.StringToTimeDurationHookFunc(), @@ -953,9 +952,14 @@ func defaultDecoderConfig(output any, opts ...DecoderConfigOption) *mapstructure stringToWeakSliceHookFunc(","), ), } + for _, opt := range opts { opt(c) } + + // Do not allow overwriting the output + c.Result = output + return c }