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

Newline are not preserved when using > for strings (for both read and write operations) #563

Open
AntoineGagne opened this issue Oct 13, 2020 · 4 comments
Labels

Comments

@AntoineGagne
Copy link

Describe the bug

When a string using > is present in the YAML, the string will be inlined following a read or write.

version of yq: 3.4.0
operating system: Ubuntu 18.04.4 LTS

Input YAML:

test.yml:

---
test: >
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
    veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
    commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
    velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
    cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
    est laborum.

Output YAML:

test: >
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Command
The command you ran:

yq read test.yml

Actual behavior

As seen in the previous snippet, it seems as though the strings are joined on newlines.

Expected behavior

The string should be kept as is. The current output does not seem to be equivalent with the input one.

Additional context

The same behaviour is also true with the write command. If there is a string using > inside the YAML document and the write command is used, it will inlined as in the read command.

@MikyStar
Copy link

MikyStar commented Oct 3, 2021

Any news about it ?

@mikefarah
Copy link
Owner

Hi - sorry I must have missed this!

This is an issue with the underlying go-yaml parser - which I don't have control of unfortunately. I beleive there are issues raised against it already.

The good news is that it is a cosmetic issue, the > block indicator replaces newlines with spaces (see http://yaml-multiline.info/ for examples) - so although it does affect the readability of your yaml file - it's not affecting the actual content.

@MikyStar
Copy link

MikyStar commented Oct 4, 2021

Hi !

The problem is that I got to differentiate a regular space and an actual line break so that I can directly put a whole formatted file as multiline string variable

@mikefarah
Copy link
Owner

mikefarah commented Oct 4, 2021 via email

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