File tree 2 files changed +18
-5
lines changed
2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -110,18 +110,24 @@ func (k *Key) Value() string {
110
110
return k .value
111
111
}
112
112
113
- // ValueWithShadows returns raw values of key and its shadows if any.
113
+ // ValueWithShadows returns raw values of key and its shadows if any. Shadow
114
+ // keys with empty values are ignored from the returned list.
114
115
func (k * Key ) ValueWithShadows () []string {
115
116
if len (k .shadows ) == 0 {
116
117
if k .value == "" {
117
118
return []string {}
118
119
}
119
120
return []string {k .value }
120
121
}
121
- vals := make ([]string , len (k .shadows )+ 1 )
122
- vals [0 ] = k .value
123
- for i := range k .shadows {
124
- vals [i + 1 ] = k .shadows [i ].value
122
+
123
+ vals := make ([]string , 0 , len (k .shadows )+ 1 )
124
+ if k .value != "" {
125
+ vals = append (vals , k .value )
126
+ }
127
+ for _ , s := range k .shadows {
128
+ if s .value != "" {
129
+ vals = append (vals , s .value )
130
+ }
125
131
}
126
132
return vals
127
133
}
Original file line number Diff line number Diff line change @@ -57,6 +57,13 @@ func TestKey_AddShadow(t *testing.T) {
57
57
assert .NoError (t , k .AddShadow ("ini" ))
58
58
assert .Equal (t , []string {"ini" , "ini.v1" }, k .ValueWithShadows ())
59
59
})
60
+
61
+ t .Run ("ignore empty shadow values" , func (t * testing.T ) {
62
+ k := f .Section ("" ).Key ("empty" )
63
+ assert .NoError (t , k .AddShadow ("" ))
64
+ assert .NoError (t , k .AddShadow ("ini" ))
65
+ assert .Equal (t , []string {"ini" }, k .ValueWithShadows ())
66
+ })
60
67
})
61
68
62
69
t .Run ("allow duplicate shadowed values" , func (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments