yq icon indicating copy to clipboard operation
yq copied to clipboard

Newline are not preserved when using `>` for strings (for both read and write operations)

Open AntoineGagne opened this issue 4 years ago • 4 comments

Describe the bug

When a string using > is present in the YAML, the string will be inlined following a read or write.

version of yq: 3.4.0 operating system: Ubuntu 18.04.4 LTS

Input YAML:

test.yml:

---
test: >
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
    veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
    commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
    velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
    cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
    est laborum.

Output YAML:

test: >
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Command The command you ran:

yq read test.yml

Actual behavior

As seen in the previous snippet, it seems as though the strings are joined on newlines.

Expected behavior

The string should be kept as is. The current output does not seem to be equivalent with the input one.

Additional context

The same behaviour is also true with the write command. If there is a string using > inside the YAML document and the write command is used, it will inlined as in the read command.

AntoineGagne avatar Oct 13 '20 17:10 AntoineGagne

Any news about it ?

MikyStar avatar Oct 03 '21 22:10 MikyStar

Hi - sorry I must have missed this!

This is an issue with the underlying go-yaml parser - which I don't have control of unfortunately. I beleive there are issues raised against it already.

The good news is that it is a cosmetic issue, the > block indicator replaces newlines with spaces (see http://yaml-multiline.info/ for examples) - so although it does affect the readability of your yaml file - it's not affecting the actual content.

mikefarah avatar Oct 03 '21 23:10 mikefarah

Hi !

The problem is that I got to differentiate a regular space and an actual line break so that I can directly put a whole formatted file as multiline string variable

MikyStar avatar Oct 04 '21 00:10 MikyStar

In that case you will need to use a different string block indicator, have a look at that yaml multiline site, I think you need to use '|'


From: Mike AUBENAS @.> Sent: Monday, October 4, 2021 11:19:01 AM To: mikefarah/yq @.> Cc: Mike Farah @.>; Comment @.> Subject: Re: [mikefarah/yq] Newline are not preserved when using > for strings (for both read and write operations) (#563)

Hi !

The problem is that I got to differentiate a regular space and an actual line break so that I can directly put a whole formatted file as multiline string variable

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/mikefarah/yq/issues/563#issuecomment-933058087, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAIZHNI57B5TJFYLBBTJL5TUFDXHLANCNFSM4SPLB2OA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

mikefarah avatar Oct 04 '21 01:10 mikefarah