mustangostang / spyc

A simple YAML loader/dumper class for PHP
MIT License
701 stars 206 forks source link

YAMLDump: Strings don't get quoted properly #53

Open lukasbestle opened 7 years ago

lukasbestle commented 7 years ago

Test case:

$data = [
    [
        'name' => 'Lorem ipsum',
        'quote' => 'Dolor sit amet.'
    ],
    [
        'name' => 'Consetetur sadipscing',
        'quote' => '"Elitr sed diam nonumy eirmod."'
    ]
];

echo Spyc::YAMLDump($data);

Also see https://github.com/getkirby/panel/issues/892#issuecomment-233149158.

Expected behavior:

The second entry is quoted by Spyc so that the quotes around the string get preserved:

- 
  name: Lorem ipsum
  quote: Dolor sit amet.
- 
  name: Consetetur sadipscing
  quote: '"Elitr sed diam nonumy eirmod."'

Actual behavior:

The string is used as-is without quoting:

- 
  name: Lorem ipsum
  quote: Dolor sit amet.
- 
  name: Consetetur sadipscing
  quote: "Elitr sed diam nonumy eirmod."

When parsing that YAML string again, the quotes are removed.