yq
yq copied to clipboard
headComment and footComment not working correctly for multiple documents
Describe the bug
The headComment
operator does not work correctly if I run it for multiple documents in a file. The same goes for footComment
.
Version of yq: 4.14.2 Operating system: linux Installed via: binary
Input Yaml
---
# head1
ab: cd
# foot1
---
# head2
ab: cd
# foot2
Command
yq e '. | headComment' test.yaml
Actual behavior
head1
---
Expected behavior
head1
---
head2
The output is the same for footComment
:
Command
yq e '. | footComment' test.yaml
Actual behavior
foot1
---
Expected behavior
foot1
---
foot2
Doh I should have picked that up - sorry, will fix.
On closer inspection, this is an issue with the underling go-yaml parser (https://github.com/go-yaml/yaml/issues/610, https://github.com/go-yaml/yaml/issues/695).
"head2" is somehow being associated as the head comment of the key 'ab' and not the document node, and there's a similar issue for "foot2".
Note sure what yq
could do about this without stuffing up other scenarios :/
As a workaround/hack, you can recursively match the nodes that have the comments attached to them:
yq e '... | headComment | select(. != "")' examples/data1.yaml
head1
---
head2
@mikefarah yes, that worked. Thanks a lot for hint 👍
Since the bug is still prevailing I would leave this issue open until it is fixed in go-yaml/yaml. Do you think we should open a separate bug report?
Yeah, though there hasn't been much action on that repo for a while :/
From: MisterMX @.> Sent: Tuesday, November 23, 2021 8:30:37 PM To: mikefarah/yq @.> Cc: Mike Farah @.>; Mention @.> Subject: Re: [mikefarah/yq] headComment and footComment not working correctly for multiple documents (Issue #1007)
@mikefarahhttps://github.com/mikefarah yes, that worked. Thanks a lot for hint 👍
Since the bug is still prevailing I would leave this issue open until it is fixed in go-yaml/yamlhttps://github.com/go-yaml/yaml. Do you think we should open a separate bug report?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/mikefarah/yq/issues/1007#issuecomment-976329358, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAIZHNO3QDTGRS57CLPTRATUNNNL3ANCNFSM5IJ7LJKA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
I filed an issue. Let's see what happens: https://github.com/go-yaml/yaml/issues/801