mustangostang / spyc

A simple YAML loader/dumper class for PHP
MIT License
707 stars 207 forks source link

Spyc cannot parse unordered list items that are a single dash "-" #26

Closed quicksketch closed 11 years ago

quicksketch commented 11 years ago

Hi there,

I'm comparing the Spyc with the Symfony YAML parser. In my testing, I found that Spyc incorrectly parses hyphens cannot read incorrect hyphens when uses in a list. Take the following YAML example:

    - One
    - Two
    - -
    - Three

In Spyc, this converts to a PHP array like this:

array(
  0 => 'One',
  1 => 'Two',
  2 => '',
  3 => 'Three',
);

But it should be:

array(
  0 => 'One',
  1 => 'Two',
  2 => '-',
  3 => 'Three',
);

This problem can also be solved by adding quotes around the troublesome hyphen in the original YAML, but Symfony's default exporter does not include this in generated YAML, making it so an exported YAML file from Symfony will contain an error when read by Spyc.

I understand Symfony and Spyc implement different versions of the YAML standard, and indeed Symfony might be in the wrong here, per the 1.0 spec at least:

Indicators are special characters that are used to describe the structure of a YAML document. In general, they cannot be used as the first character of a plain scalar.

So this may not be a Spyc decoder issue but a Symfony encoder issue. I thought I'd report it here nonetheless.

EDIT: I updated the title and description to be clear that I think this is an encoding issue. It probably should just be invalid, but I'm double-checking.