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

Invalid yaml output when deleting list/object with comment #1976

Open
edonin opened this issue Mar 12, 2024 · 1 comment
Open

Invalid yaml output when deleting list/object with comment #1976

edonin opened this issue Mar 12, 2024 · 1 comment
Labels

Comments

@edonin
Copy link

edonin commented Mar 12, 2024

Describe the bug
When you delete the last element of a list or a map, but if there is a comment on this list, the generated yaml is not valid. The empty list/map is put on a new line without any space behind.

Version of yq: 4.42.1
Operating system: windows
Installed via: binary release

Input Yaml
data1.yml:

test:
  foo: #bar
    - bar

data2.yml:

test:
  foo: #bar
    bar: 1

Command
The command you ran:

yq e "del(.test.foo[])" data1.yaml
yq e "del(.test.foo.bar)" data2.yaml

Actual behavior

test:
  foo: #bar
[]

test:
  foo: #bar
{}

Expected behavior

test:
  foo: #bar
    []

test:
  foo: #bar
    {}
@danielefranceschi
Copy link

danielefranceschi commented Mar 12, 2024

Happened also in v4.40.5 linux/amd64.
Possible duplicate: #1729

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

2 participants