mikefarah / yq

yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
https://mikefarah.gitbook.io/yq/
MIT License
12.37k stars 603 forks source link

Spurious newline added with `yq -i` when multiline strings are present #2074

Open cbeck88 opened 5 months ago

cbeck88 commented 5 months ago

Describe the bug

When editing certain .yaml files in-place with yq that contain multiline strings, it adds newlines that don't belong. It adds more newlines every time it runs over these files.

Version of yq: 4.43.1 Operating system: linux Installed via: binary release

Input Yaml

data1.yaml:

image:
  tag: "0.55.3"
env:
  MM_CONFIGS: >-
    '{
      "params": {
        "a": "400",
        "b": "200"
      }
     }'

Command

yq eval ".image.tag = \"0.55.4\"" -i data1.yaml

Actual behavior

image:
  tag: "0.55.4"
env:
  MM_CONFIGS: >-
    '{

      "params": {
        "a": "400",
        "b": "200"
      }
     }'

Expected behavior

image:
  tag: "0.55.4"
env:
  MM_CONFIGS: >-
    '{
      "params": {
        "a": "400",
        "b": "200"
      }
     }'

Additional context

I haven't been able to find any good workarounds for this issue. Any tips short of a full fix would be greatly appreciated. Thanks