yq
yq copied to clipboard
Multiline strings with a line ending with a white space are represented inline
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:
- An inline representation:
content: "literal\n\ttext\n"
- 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).
Any timeline or targeted release version to fix this bug?
I came across the same problem when formating a yaml manifest, but the trailing white space was unintentional though.
Duplicate of #566 which depends on go-yaml/yaml#880
Seems no solution currently except removing the trailing spaces in the multi-line block.