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

CRLF Issue with document headers #1871

Open
mikefarah opened this issue Nov 18, 2023 · 3 comments
Open

CRLF Issue with document headers #1871

mikefarah opened this issue Nov 18, 2023 · 3 comments

Comments

@mikefarah
Copy link
Owner

          @mikefarah I'm not sure if I should be reporting this here, as it seems to be related to the CrLf handling, or if I should open a new issue for this.... Let me know if I need to move this to a new issue.

Platform: Windows
Input file:

---
# document 1 start comment
test:
  sub:
   key: value
---
# document 2 start comment
foo:
  bar:
   key: value

Line Ending: CrLf

yq '.' test-in.yaml:

---
# document 1 start comment
test:
  sub:
    key: value
# document 2 start comment
---
foo:
  bar:
    key: value

Note how the "document 2 start comment" has moved from the top of the second document to the bottom of the first document!

This is causing havoc with the Kubernetes manifest that I'm manipulating with yq...

If I explicitly change the line endings of test-in.yaml to UNIX-style "Lf", the issue does not appear.

Originally posted by @boekhold in #1860 (comment)

@mikefarah
Copy link
Owner Author

Digging into this - it seems like its an issue with the underlying go-yaml parse :/ possibly related to go-yaml/yaml#893. If it helps, I noticed that if the input yaml has an extra line break between the document separator and the document 2 comment, then it works

---
# document 1 start comment
foo: dog
---

# document 2 start comment
foo: cat

@boekhold
Copy link

boekhold commented Apr 18, 2024

I noticed release https://github.com/mikefarah/yq/releases/tag/v4.40.1 which mentions removing the dependency on go-yaml, so I figured I give this a test (with v4.43.1), and unfortunately this didn't fix this issue. In fact, the output is different now:

# document 1 start comment
test:
  sub:
    key: value
# document 2 start comment

---
foo:
  bar:
    key: value

Notice the additional blank line between "document 2 start comment" and the document separator.

@boekhold
Copy link

Just a note on why this matters... If you use yq as a post processor for Helm charts, the resulting manifest file will be different on UNIX/Linux compared to the one on Windows. If you first install your Helm chart from Linux, and then update the identical chart from Windows, Helm will consider the charts different, and actually update the k8s objects, even though they really are identical.

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

No branches or pull requests

2 participants