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

yaml top document separator removed #879

Closed
rockandska opened this issue Jul 2, 2021 · 8 comments
Closed

yaml top document separator removed #879

rockandska opened this issue Jul 2, 2021 · 8 comments
Labels
Milestone

Comments

@rockandska
Copy link

rockandska commented Jul 2, 2021

Describe the bug

When editing Yaml files with --- at its top, those hyphens are removed

Version of yq: 4.9.6
Operating system: linux
Installed via: docker

Command

$ cat << EOF > /tmp/test.yml
---
test: test
EOF
$ docker run --rm -v "/tmp":/workdir mikefarah/yq -i eval '.test = 1' test.yml

Actual behavior

$ cat /tmp/test.yml
test: 1

Expected behavior

$ cat /tmp/test.yml
---
test: 1
@rockandska rockandska changed the title yaml top hyphen removed with --inplace yaml top hyphen removed Jul 2, 2021
@mikefarah
Copy link
Owner

Yep - this is a known formatting issue with the underlying go-yaml parser.

Note that this only affects the readability of the document

@mikefarah mikefarah changed the title yaml top hyphen removed yaml top document separator removed Jul 7, 2021
@rockandska
Copy link
Author

Note that this only affects the readability of the document

and raise an error with yamlint

@mikefarah
Copy link
Owner

Oh that's interesting - I'm not aware of it being recommended in the yaml spec shrug.

It might be worth raising the issue in go-yaml.

@ikorchynskyi
Copy link

A kind of an ugly workaround, if you really need it:

$ cat sample.yml
---
type: shelter
pets:
  - a: cat
  - b: dog

$ yq e '.' sample.yml
type: shelter
pets:
  - a: cat
  - b: dog

$ yq e '["---",.][]' sample.yml
---
type: shelter
pets:
  - a: cat
  - b: dog

@mikefarah
Copy link
Owner

Well that's unexpected...I'm not sure how that works! Gotta look into that.

@mikefarah
Copy link
Owner

Oh I see now - nice trick

@mikefarah
Copy link
Owner

I'm going to fix this up in the next release

@mikefarah mikefarah added this to the 4.9.9 milestone Jul 14, 2021
@mikefarah
Copy link
Owner

I've put a fix in yq to check and persist the top document separator in 4.10.0 :)

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