Skip to content
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

comment is visible when some feature like pick or length #1231

Closed
gabs77 opened this issue May 30, 2022 · 4 comments
Closed

comment is visible when some feature like pick or length #1231

gabs77 opened this issue May 30, 2022 · 4 comments
Labels

Comments

@gabs77
Copy link

gabs77 commented May 30, 2022

Comment is visible when some feature like pick or length

Version of yq: 4.25.X
Operating system: linux/windows

Input Yaml
data1.yml:

# --------------------------------------------------
# It's a test with comment
# --------------------------------------------------
test:
  - name: a
  - name: b
  - name: c
groups:
  - name: a
  - name: b
  - name: c
  - name: c

data2.yml:

# --------------------------------------------------
# It's a test with comment
# --------------------------------------------------
groups:
  - name: d

Command
The command you ran:

 yq '[ .groups[].name | select(.=="a") ] | length' data1.yml

Actual behavior

# --------------------------------------------------
# It's a test with comment
# --------------------------------------------------
1

Expected behavior

1

Additional context
Same problem with the pick feature
yq 'pick(["groups"]) | explode(.) as $item ireduce ({}; . *+ $item)' data1.yml data2.yml --no-doc --prettyPrint

Actual behavior

# --------------------------------------------------
# It's a test with comment
# --------------------------------------------------
groups:
  - name: a
  - name: b
  - name: c
  - name: c
# --------------------------------------------------
# It's a test with comment
# --------------------------------------------------
groups:
  - name: d

Expected behavior

groups:
  - name: a
  - name: b
  - name: c
  - name: c
groups:
  - name: d
@mikefarah
Copy link
Owner

mikefarah commented May 31, 2022

Hi - I agree with the length operator, the comments should not come through will fix in the next release. Till then you can
[ .groups[].name | select(.=="a") ] | length | . headComment = ""

For pick I actually think keeping the comments makes sense - as it's basically a filter on the map/array (rather than a new calculated result). Use . headComment = "" or even ... comments="" to remove the comments.

edit: formatting

@gabs77
Copy link
Author

gabs77 commented May 31, 2022

Perfect
Thanks

@oramirite
Copy link

oramirite commented Jun 3, 2022

Thanks, this crept up on me today and I thought I was going crazy. Seems to affect has() as well. I'm using this to inspect a cloud-config file, so I started to get #cloud-config in my results. Got really confusing, since it should really just be a sanitized true/false no matter what.

@mikefarah
Copy link
Owner

Fixed in v4.25.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants