yq
yq copied to clipboard
Extra space causes multiline string rendered as single line string
Describe the bug
Having extra space at the end of a line in a multiline string seems to causes yq to render it as single line string
Version of yq: 4.35.2 & 4.25.1 Operating system: Mac Installed via: Homebrew & GitHub Release
Input Yaml test.yml:
a: |
{
"b": 1
}
(Note that there's extra space after 1
).
Command
yq test.yml
Actual behavior
a: "{\n \"b\": 1 \n}\n"
Expected behavior
a: |
{
"b": 1
}
Additional context
If you reference field a
during eval (i.e. yq '.a' test.yml
) it will render as multiline string (with the extra space still intact):
{
"b": 1
}
If you try patch test.yml
with this (again, note the extra trailing space):
--- test.yaml 2023-10-17 17:53:03
+++ test.yaml.new 2023-10-17 17:58:15
@@ -1,4 +1,4 @@
a: |
{
- "b": 1
+ "b": 1
}
yq test.yaml
still renders it as multiline block.
a: |
{
"b": 1
}
This bug prevents me using yq since it reformats multiline strings that are used as messageTemplates for git commit messages into a one-liner and generates wrong diffs and merge conflicts in the end.
The yamls are as part of a FluxCD Configuration - Image Update Config (https://fluxcd.io/flux/components/image/imageupdateautomations/).
Hope to replace my current dumb "sed" usages with yq again soon, since sed-usage limits me in another aspect at the moment.