mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Fixed multi doc anchor bug #1861
This commit is contained in:
parent
79a50b9c20
commit
c7ef946031
@ -20,6 +20,9 @@ type yamlDecoder struct {
|
||||
leadingContent string
|
||||
bufferRead bytes.Buffer
|
||||
|
||||
// anchor map persists over multiple documents for convenience.
|
||||
anchorMap map[string]*CandidateNode
|
||||
|
||||
readAnything bool
|
||||
firstFile bool
|
||||
documentIndex uint
|
||||
@ -95,6 +98,7 @@ func (dec *yamlDecoder) Init(reader io.Reader) error {
|
||||
dec.decoder = *yaml.NewDecoder(readerToUse)
|
||||
dec.firstFile = false
|
||||
dec.documentIndex = 0
|
||||
dec.anchorMap = make(map[string]*CandidateNode)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -121,7 +125,7 @@ func (dec *yamlDecoder) Decode() (*CandidateNode, error) {
|
||||
|
||||
candidateNode := CandidateNode{document: dec.documentIndex}
|
||||
// don't bother with the DocumentNode
|
||||
err = candidateNode.UnmarshalYAML(yamlNode.Content[0], make(map[string]*CandidateNode))
|
||||
err = candidateNode.UnmarshalYAML(yamlNode.Content[0], dec.anchorMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -32,6 +32,13 @@ var yamlFormatScenarios = []formatScenario{
|
||||
input: "[null]",
|
||||
expected: "[null]\n",
|
||||
},
|
||||
{
|
||||
description: "multi document anchor map",
|
||||
skipDoc: true,
|
||||
input: "a: &remember mike\n---\nb: *remember",
|
||||
expression: "explode(.)",
|
||||
expected: "a: mike\n---\nb: mike\n",
|
||||
},
|
||||
{
|
||||
description: "basic - [~]",
|
||||
skipDoc: true,
|
||||
|
Loading…
Reference in New Issue
Block a user