mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
fix: do not allow overwriting the mapstructure output
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
parent
7dbe493dd1
commit
5964efa262
1 changed files with 5 additions and 1 deletions
6
viper.go
6
viper.go
|
@ -949,7 +949,6 @@ func (v *Viper) decodeStructKeys(input any, opts ...DecoderConfigOption) ([]stri
|
||||||
func defaultDecoderConfig(output any, opts ...DecoderConfigOption) *mapstructure.DecoderConfig {
|
func defaultDecoderConfig(output any, opts ...DecoderConfigOption) *mapstructure.DecoderConfig {
|
||||||
c := &mapstructure.DecoderConfig{
|
c := &mapstructure.DecoderConfig{
|
||||||
Metadata: nil,
|
Metadata: nil,
|
||||||
Result: output,
|
|
||||||
WeaklyTypedInput: true,
|
WeaklyTypedInput: true,
|
||||||
DecodeHook: mapstructure.ComposeDecodeHookFunc(
|
DecodeHook: mapstructure.ComposeDecodeHookFunc(
|
||||||
mapstructure.StringToTimeDurationHookFunc(),
|
mapstructure.StringToTimeDurationHookFunc(),
|
||||||
|
@ -957,9 +956,14 @@ func defaultDecoderConfig(output any, opts ...DecoderConfigOption) *mapstructure
|
||||||
stringToWeakSliceHookFunc(","),
|
stringToWeakSliceHookFunc(","),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(c)
|
opt(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do not allow overwriting the output
|
||||||
|
c.Result = output
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue