Skip to content

Commit

Permalink
Fixed explode for aliases to scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Feb 6, 2020
1 parent d40ad96 commit 72cd3e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions cmd/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,21 @@ pointer: *value-pointer`
test.AssertResult(t, expectedOutput, result.Output)
}

func TestReadMergeAnchorsExplodeSimpleValueForValueCmd(t *testing.T) {
content := `value: &value-pointer the value
pointer: *value-pointer`
filename := test.WriteTempYamlFile(content)
defer test.RemoveTempYamlFile(filename)

cmd := getRootCommand()
result := test.RunCmd(cmd, fmt.Sprintf("read -X %s value", filename))
if result.Error != nil {
t.Error(result.Error)
}
expectedOutput := `the value`
test.AssertResult(t, expectedOutput, result.Output)
}

func TestReadMergeAnchorsExplodeCmd(t *testing.T) {
cmd := getRootCommand()
result := test.RunCmd(cmd, "read -X ../examples/merge-anchor.yaml")
Expand Down
8 changes: 7 additions & 1 deletion pkg/yqlib/data_navigator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ func (n *navigator) Traverse(value *yaml.Node, path []string) error {
}

func (n *navigator) doTraverse(value *yaml.Node, head string, tail []string, pathStack []interface{}) error {

if value.Kind == yaml.ScalarNode {
return n.navigationStrategy.Visit(NewNodeContext(value, head, tail, pathStack))
}

log.Debug("head %v", head)
DebugNode(value)

var errorDeepSplatting error
if head == "**" && value.Kind != yaml.ScalarNode {
if head == "**" {
if len(pathStack) == 0 || pathStack[len(pathStack)-1] != "<<" {
errorDeepSplatting = n.recurse(value, head, tail, pathStack)
}
Expand Down

0 comments on commit 72cd3e4

Please sign in to comment.