Skip to content
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

Strings with question marks get quotes removed #96

Open
lyz-code opened this issue Dec 10, 2022 · 0 comments
Open

Strings with question marks get quotes removed #96

lyz-code opened this issue Dec 10, 2022 · 0 comments

Comments

@lyz-code
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant