8000 YAML does not escape hyphens when used in sequences · Issue #9039 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

YAML does not escape hyphens when used in sequences #9039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
quicksketch opened this issue Sep 15, 2013 · 2 comments
Closed

YAML does not escape hyphens when used in sequences #9039

quicksketch opened this issue Sep 15, 2013 · 2 comments

Comments

@quicksketch
Copy link

I was comparing Symfony's compatibility with Spyc and found an issue with Symfony's YAML encoder.

The issue arose when encoding an array like this:

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

Symfony produces a YAML file like this:

- One
- Two
- -
- Three
- '|'
- Four

The hyphen is not quoted, but it should be. Other "Indicators" from the YAML standard seem to be encoded, like the pipe character in this example. Without quoting, when Spyc tries to read this YAML file, it considers the hyphen to be an empty entry, like this:

array(
  0 => 'One',
  1 => 'Two',
  2 => '',
  3 => 'Three',
  4 => '|',
  5 => 'Four',
);

The matching issue at Spyc is here: mustangostang/spyc#26, but I think this is an issue with Symfony's encoder, considering it's the one generating incorrect YAML.

@stof
Copy link
Member
stof commented Oct 10, 2013

There is actually 2 bugs here:

  • a dumper bug
  • a parser bug. The behavior of spyc is consistent with the parsing done by pyyaml in Python and the ya2yaml gem (try it on http://yamllint.com/ with the example above)

stof added a commit to stof/symfony that referenced this issue Oct 10, 2013
Dashes need to be escaped in character sets in regexes as they are used to
specify a range otherwise.
Refs symfony#9039
fabpot added a commit that referenced this issue Oct 11, 2013
…hen dumping (stof)

This PR was merged into the 2.2 branch.

Discussion
----------

[Yaml] Fixed the escaping of strings starting with a dash when dumping

Dashes need to be escaped in character sets in regexes as they are used to specify a range otherwise.
It fixes the dumper bug reported in #9039 (the parsing issue is not fix here)

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | partially #9039
| License       | MIT
| Doc PR        | n/a

Commits
-------

af369ae [Yaml] Fixed the escaping of strings starting with a dash when dumping
@jakzal
Copy link
Contributor
jakzal commented Dec 23, 2013

This is fixed now.

@jakzal jakzal closed this as completed Dec 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0