saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.19k stars 5.48k forks source link

[BUG] extra empty lines added by yaml serializer on multiline values #65598

Closed sblaisot closed 12 months ago

sblaisot commented 12 months ago

Description

When using yaml serializer on multiline values, it doubled every line break, leading to extra empty lines

Setup

Pillar:

mytest:
  value1: "foobar"
  value2: 42
  value3: |
    multiline
    string

State:

mytest:
  file.serialize:
    - name: /tmp/mytest
    - user: root
    - group: root
    - mode: "0644"
    - dataset_pillar: mytest
    - formatter: yaml

created file /tmp/mytest:

# cat /tmp/mytest 
value1: foobar
value2: 42
value3: 'multiline

  string

  '

also able to reproduce with:

# salt-call slsutil.serialize yaml obj='{some: "multiline\nstring"}'
local:
    {some: 'multiline

        string'}

Please be as specific as possible and give set-up details.

Steps to Reproduce the behavior

# salt-call slsutil.serialize yaml obj='{some: "multiline\nstring"}'
local:
    {some: 'multiline

        string'}

Expected behavior

# salt-call slsutil.serialize yaml obj='{some: "multiline\nstring"}'
local:
    {some: 'multiline    
        string'}

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.) ```yaml # salt-call -V Salt Version: Salt: 3005.1 Dependency Versions: cffi: 1.14.6 cherrypy: 18.6.1 dateutil: 2.8.1 docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed Jinja2: 3.1.0 libgit2: Not Installed M2Crypto: Not Installed Mako: Not Installed msgpack: 1.0.2 msgpack-pure: Not Installed mysql-python: Not Installed pycparser: 2.21 pycrypto: Not Installed pycryptodome: 3.9.8 pygit2: Not Installed Python: 3.9.16 (main, Jan 6 2023, 22:50:03) python-gnupg: 0.4.8 PyYAML: 5.4.1 PyZMQ: 23.2.0 smmap: Not Installed timelib: 0.2.4 Tornado: 4.5.3 ZMQ: 4.3.4 System Versions: dist: debian 10 buster locale: utf-8 machine: x86_64 release: 4.19.0-24-cloud-amd64 system: Linux version: Debian GNU/Linux 10 buster ```
sblaisot commented 12 months ago

ok, it seems there is no bug here and it is per YAML spec.

it looks ugly for the eyes but works as expected for the machine and can be loaded to get the original multiline string.

The default yaml.dump string formatter doesn't take the most readable form of multiline string.

So I'm closing this issue