file parser: skip nil value.
This commit is contained in:
parent
1dc6f39b55
commit
44a244b1cb
2 changed files with 18 additions and 0 deletions
|
@ -28,6 +28,10 @@ func decodeRaw(node *parser.Node, vData reflect.Value, filters ...string) error
|
||||||
sortedKeys := sortKeys(vData, filters)
|
sortedKeys := sortKeys(vData, filters)
|
||||||
|
|
||||||
for _, key := range sortedKeys {
|
for _, key := range sortedKeys {
|
||||||
|
if vData.MapIndex(key).IsNil() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
value := reflect.ValueOf(vData.MapIndex(key).Interface())
|
value := reflect.ValueOf(vData.MapIndex(key).Interface())
|
||||||
|
|
||||||
child := &parser.Node{Name: key.String()}
|
child := &parser.Node{Name: key.String()}
|
||||||
|
|
|
@ -524,6 +524,20 @@ func Test_decodeRawToNode(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "nil value",
|
||||||
|
data: map[string]interface{}{
|
||||||
|
"fii": map[interface{}]interface{}{
|
||||||
|
"fuu": nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: &parser.Node{
|
||||||
|
Name: "traefik",
|
||||||
|
Children: []*parser.Node{
|
||||||
|
{Name: "fii"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
|
|
Loading…
Add table
Reference in a new issue