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

Multiline strings with a line ending with a white space are represented inline #1681

Open
denysvitali opened this issue May 30, 2023 · 3 comments
Labels

Comments

@denysvitali
Copy link

Describe the bug

Using the "literal style" YAML spec page as an example and the following string:

literal\n\ttext\n

there are two ways of representing it:

  1. An inline representation:
content: "literal\n\ttext\n"
  1. A block representation:
content: |


   literal


   text

Depending on the context, one might be easier to read than the other.

Assuming the following two cases (white space represented by for clarity):

a)

/tmp/a.txt

TEST
1234
00000000: 5445 5354 0a31 3233 340a                 TEST.1234.

b)

/tmp/b.txt

TEST•
1234
00000000: 5445 5354 200a 3132 3334 0a              TEST .1234.

This is the output of the following command:

yq -n '.content = load_str("/tmp/{a,b}.txt")'

a)

content: |
  TEST
  1234

b)

content: "TEST \n1234\n"

Version of yq: 4.34.1
Operating system: MacOS
Installed via: Homebrew

Expected behavior

For clarity, it would be best if the result of encoding a multi-line string ending with •\n (0x20, 0x0a) would not mess up the whole representation - depending on the use.
It would be interesting to allow the user to define this behaviour - some times you really want to make clear that there is a space before a new line - whereas some times you don't really care (e.g: XML).

Additional context

This might be nit-picking, but the output really looks ugly when you have a multi-line document that out of nowhere becomes encoded in a single-line string just because one of the N lines contains a (0x20, 0x0a).

@denysvitali denysvitali changed the title Multiline strings with a line ending with a white space are represented as single line Multiline strings with a line ending with a white space are represented inline May 30, 2023
@Orrimp
Copy link

Orrimp commented Jul 14, 2023

Any timeline or targeted release version to fix this bug?

@networkhermit
Copy link

I came across the same problem when formating a yaml manifest, but the trailing white space was unintentional though.

@arikkfir
Copy link

arikkfir commented Sep 8, 2023

Duplicate of #566 which depends on go-yaml/yaml#880

Seems no solution currently except removing the trailing spaces in the multi-line block.

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

4 participants