Skip to content

Commit 7dbe493

Browse files
committed
fix: do not allow setting dependencies to nil values
Signed-off-by: Mark Sagi-Kazar <[email protected]>
1 parent 35a4605 commit 7dbe493

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

encoding.go

+12
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,32 @@ type CodecRegistry interface {
5858
// WithEncoderRegistry sets a custom [EncoderRegistry].
5959
func WithEncoderRegistry(r EncoderRegistry) Option {
6060
return optionFunc(func(v *Viper) {
61+
if r == nil {
62+
return
63+
}
64+
6165
v.encoderRegistry = r
6266
})
6367
}
6468

6569
// WithDecoderRegistry sets a custom [DecoderRegistry].
6670
func WithDecoderRegistry(r DecoderRegistry) Option {
6771
return optionFunc(func(v *Viper) {
72+
if r == nil {
73+
return
74+
}
75+
6876
v.decoderRegistry = r
6977
})
7078
}
7179

7280
// WithCodecRegistry sets a custom [EncoderRegistry] and [DecoderRegistry].
7381
func WithCodecRegistry(r CodecRegistry) Option {
7482
return optionFunc(func(v *Viper) {
83+
if r == nil {
84+
return
85+
}
86+
7587
v.encoderRegistry = r
7688
v.decoderRegistry = r
7789
})

finder.go

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import (
99
// WithFinder sets a custom [Finder].
1010
func WithFinder(f Finder) Option {
1111
return optionFunc(func(v *Viper) {
12+
if f == nil {
13+
return
14+
}
15+
1216
v.finder = f
1317
})
1418
}
@@ -34,6 +38,10 @@ func (c *combinedFinder) Find(fsys afero.Fs) ([]string, error) {
3438
var errs []error
3539

3640
for _, finder := range c.finders {
41+
if finder == nil {
42+
continue
43+
}
44+
3745
r, err := finder.Find(fsys)
3846
if err != nil {
3947
errs = append(errs, err)

viper.go

+4
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ type StringReplacer interface {
247247
// EnvKeyReplacer sets a replacer used for mapping environment variables to internal keys.
248248
func EnvKeyReplacer(r StringReplacer) Option {
249249
return optionFunc(func(v *Viper) {
250+
if r == nil {
251+
return
252+
}
253+
250254
v.envKeyReplacer = r
251255
})
252256
}

0 commit comments

Comments
 (0)