-
-
Notifications
You must be signed in to change notification settings - Fork 712
Open
Description
Describe the bug
From v4.46.1 the merged output of documents with anchors has changed.
Version of yq: 4.46.1+
Operating system: mac + linux
Installed via: homebrew + github binaries
Input Yaml
input.yml:
map1: &map
key1: true
map2:
<<: *map
map3:
<<: *map
addkey: true
map4: *map
---
map1:
key1: replace
newkey: truev4.45.4
In v4.45.4 you can do the explode before or after the document merge and get the same expected result:
$ ./yq-v4.45.4 eval-all '. as $item ireduce ({}; . * $item ) | explode(.)' input.yaml
map1:
key1: replace
newkey: true
map2:
key1: true
map3:
key1: true
addkey: true
map4:
key1: true
$ ./yq-v4.45.4 eval-all 'explode(.) as $item ireduce ({}; . * $item )' input.yaml
map1:
key1: replace
newkey: true
map2:
key1: true
map3:
key1: true
addkey: true
map4:
key1: truev4.46.1
In v4.46.1 if you explode before the merge then it mangles the maps:
$ ./yq-v4.46.1 eval-all 'explode(.) as $item ireduce ({}; . * $item )' input.yaml
map1:
key1: replace
newkey: true
map2:
"0": key1
"1": true
map3:
"0": key1
"1": true
"2": addkey
"3": true
map4:
key1: true
$ ./yq-v4.46.1 eval-all '. as $item ireduce ({}; . * $item ) | explode(.)' input.yaml
map1:
key1: replace
newkey: true
map2:
key1: true
map3:
key1: true
addkey: true
map4:
key1: truev4.48.1
v4.48.1 behaves the same as v4.46.1 but if you set --yaml-fix-merge-anchor-to-spec then it presents another issue:
$ ./yq-v4.48.1 --yaml-fix-merge-anchor-to-spec eval-all 'explode(.) as $item ireduce ({}; . * $item )' input.yaml
map1:
key1: replace
newkey: true
map2: {}
map3:
addkey: true
map4:
key1: true
$ ./yq-v4.48.1 --yaml-fix-merge-anchor-to-spec eval-all '. as $item ireduce ({}; . * $item ) | explode(.)' input.yaml
map1:
key1: replace
newkey: true
map2:
<<:
key1: true
map3:
<<:
key1: true
addkey: true
map4:
key1: true