lyz-code/yamlfix

yamlfix breaks yaml loading on strings with question mark

ginevragaudioso opened this issue · 4 comments

I have the following yaml file:

---
- key: ['value?']

which loads correctly in python with pyyaml's yaml.safe_load.

yamlfix 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 yamlfix did not remove quotes on strings with question marks (and whatever other set of characters can cause this issue), or if there was a way to disable the feature to remove quotes entirely.

Hi @ginevragaudioso , thanks for taking the time to open the issue. I can confirm the behaviour and that it's a bug that should be fixed.

It makes sense to try to fix it upstream first (ruyaml is the library we use to do the main fix of the source code), so I've opened an issue on their repo.

@ginevragaudioso @lyz-code as a workaround, until this is fixed upstream, you could set the quote_basic_values option to True once this is merged -> #189 and the string value would remain quoted.

Thanks @marcules , that change would work great for us!

The patch is available since 1.2.0 therefore I'm closing the issue. If they ever fix it upstream you could remove the patch