mk-fg / pretty-yaml

PyYAML-based module to produce a bit more pretty and readable YAML-serialized data
Do What The F*ck You Want To Public License
135 stars 29 forks source link

Serialization bug #13

Closed mpenkov closed 9 years ago

mpenkov commented 9 years ago

Given the data:

{'foo': ['bar:', 'baz']}

pyaml serializes this as:

foo:
  - bar:
  - baz

which then gets deserialized by yaml as:

{'foo': [{'bar': None}, 'baz']}

This is different to the original data. I'm not sure if this is a problem with pyaml, yaml, or something else. The problem is fixed by forcing quotes around "bar:" in the output:

foo:
  - "bar:"
  - baz

This can be achieved by:

pyaml.dump(data, stream, string_val_style="double-quoted")

Sample code to reproduce the problem:

import yaml
import pyaml
import StringIO
data = {"foo": ["bar:", "baz"]}
print data
stream = StringIO.StringIO()
pyaml.dump(data, stream)
print stream.getvalue()
data2 = yaml.load(stream.getvalue())
print data2
mk-fg commented 9 years ago

It's definitely a pyaml issue, as PyYAML does the conservative thing and quotes as much as possible, which pyaml tries to "fix", in it's deeply flawed and hacky way ;)

Should be fixed in a77add9, thanks for pointing it out!