Strings with question marks get quotes removed
Opened this issue · 0 comments
lyz-code commented
I have the following yaml file:
---
- key: ['value?']
which loads correctly in python with pyyaml's yaml.safe_load
.
ruyaml
changes the file to
---
- key: [value?]
which cannot be loaded by pyyaml's yaml.safe_load
, error being "expected ',' or ']', but got '?'"
yq
breaks similarly with error parse error: Invalid numeric literal at line 2, column 0
It would be nice if ruyaml did not remove quotes on strings with question marks (and whatever other set of characters can cause this issue).
I've assembled a small example to reproduce the issue:
from io import StringIO
import ruyaml
original_source_code = "---\n - key: ['value?']"
yaml = ruyaml.main.YAML()
yaml.indent(mapping=2, sequence=4, offset=2)
yaml.allow_duplicate_keys = True
yaml.explicit_start = True
yaml.width = 80
source_dicts = yaml.load_all(original_source_code)
string_stream = StringIO()
for source_dict in source_dicts:
yaml.dump(source_dict, string_stream)
source_code = string_stream.getvalue()
string_stream.close()
assert original_source_code == source_code
>>> AssertionError
>>> source_code
'---\n - key: [value?]\n'
Thank you
Related issue: lyz-code/yamlfix#188