yq icon indicating copy to clipboard operation
yq copied to clipboard

Extra space causes multiline string rendered as single line string

Open aufarg opened this issue 9 months ago • 1 comments

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
  }

aufarg avatar Oct 17 '23 10:10 aufarg

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.

kw-s avatar Dec 12 '23 10:12 kw-s