fix: correct visitMappingNodeFields

This commit adjusts visitMappingNodeFields so that it no longer assumes
the mapping node has unique keys.
This commit is contained in:
Ed Overton
2022-12-22 11:51:15 -05:00
parent 20b0d3c7ce
commit a0e94c1642
2 changed files with 25 additions and 13 deletions

View File

@@ -647,16 +647,16 @@ func (s MapEntrySetter) Filter(rn *RNode) (*RNode, error) {
}
content := rn.Content()
stillMissing := true
fieldStillNotFound := true
visitFieldsWhileTrue(content, func(key, value *yaml.Node, keyIndex int) bool {
if key.Value == s.Name {
content[keyIndex] = s.Key.YNode()
content[keyIndex+1] = s.Value.YNode()
stillMissing = false
fieldStillNotFound = false
}
return stillMissing
return fieldStillNotFound
})
if !stillMissing {
if !fieldStillNotFound {
return rn, nil
}