From 72cd3e4a2a47580c49a3d9330c0901ffa1375f49 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Fri, 7 Feb 2020 10:42:07 +1100 Subject: [PATCH] Fixed explode for aliases to scalars --- cmd/commands_test.go | 15 +++++++++++++++ pkg/yqlib/data_navigator.go | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cmd/commands_test.go b/cmd/commands_test.go index 9aeb7c12e43..5233fb61e8c 100644 --- a/cmd/commands_test.go +++ b/cmd/commands_test.go @@ -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") diff --git a/pkg/yqlib/data_navigator.go b/pkg/yqlib/data_navigator.go index d0c5f3f9cc3..2d031fc804a 100644 --- a/pkg/yqlib/data_navigator.go +++ b/pkg/yqlib/data_navigator.go @@ -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) }