-
-
Notifications
You must be signed in to change notification settings - Fork 661
Fix some issues around merge key/anchor handling #2400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
- Allow inline maps instead of just aliases - Disallow nested sequences - Disallow other types Closes mikefarah#2386
Wait, this actually doesn't fix |
- Allow inline maps instead of just aliases - Allow aliased sequences - Disallow other types - Use tag `!!merge` instead of key `<<` - Fix insertion index for sequence merge Closes mikefarah#2386
EDIT: nvm fixed it Ok, the excessive exploding fix I mentioned above may actually cause problems of its own: However, I don't really know how to solve this, because it depends on if the mapping node to which the merge anchor refers is also being exploded, e.g. with And apparently this issue is already present when partially exploding: |
This PR fixes multiple issues related to merge keys (
!!merge <<
):{<<: {a: 42}}
,{<<: [{a: 42}]}
), both for traversing and exploding (closes Merge key with inline map broken #2386){s: &s [{a: 42}], m: {<<: *s}}
), both for traversing and exploding (closes Explode with merge aliases throw an error #2178)){<<: [[{a: 42}]]}
){<<: 42}
{a: &a 42, m: {<<: *a}}
were reported but cases like{m: {<<: 42}}
were not. I chose to ignore all errors because otherwise traversing such a map (e.g. to correct types) becomes impossible.explode
. Previously explode would just leave out invalid merge keys. Another potential solution would be to leave them as-is.echo '{b: &b {a: &a 42}, r: *a, c: {<<: *b}}' | yq 'explode(.c)'
would yield{b: &b {a: 42}, r: *a, c: {a: 42}}
, makingr: *a
a dangling reference. Now it yields{b: &b {a: &a 42}, r: *a, c: {a: &a 42}}
.!!merge
) rather than value (<<
).I do still have a question: I saw in
operator_traverse_path_test.go
that goccy would reject at least some invalid merge types at parse time, which might make using custom tags like<<: !include file.yaml
(see #2386) impossible. Am I right about that? And does that mean that this usage will not be supported in the future? If so, that would be a bit sad. See also the note above about ignoring invalid merge keys.