Skip to content

Commit

Permalink
Can now retrieve the alias names of merge anchors #1942
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Feb 9, 2024
1 parent b55f52f commit 8cde0c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/yqlib/matchKeyString_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestDeepMatch(t *testing.T) {
ok bool
}{
{"", "", true},
{"<<", "<<", true},
{"", "x", false},
{"x", "", false},
{"abc", "abc", true},
Expand Down
2 changes: 1 addition & 1 deletion pkg/yqlib/operator_traverse_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func doTraverseMap(newMatches *orderedmap.OrderedMap, node *CandidateNode, wante
value := contents[index+1]

//skip the 'merge' tag, find a direct match first
if key.Tag == "!!merge" && !prefs.DontFollowAlias {
if key.Tag == "!!merge" && !prefs.DontFollowAlias && wantedKey != "<<" {
log.Debug("Merge anchor")
err := traverseMergeAnchor(newMatches, value, wantedKey, prefs, splat)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/yqlib/operator_traverse_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ steps:
`

var traversePathOperatorScenarios = []expressionScenario{
{
skipDoc: true,
description: "access merge anchors",
document: "foo: &foo {x: y}\nbar:\n <<: *foo\n",
expression: `.bar["<<"] | alias`,
expected: []string{
"D0, P[bar <<], (!!str)::foo\n",
},
},
{
skipDoc: true,
description: "dynamically set parent and key",
Expand Down

0 comments on commit 8cde0c8

Please sign in to comment.