First time posting here, please guide me if this is in the wrong category.
The problem
YAML1.2 was published in 2009 (14 years ago!), and widely-used parsers such as yaml-cpp have adopted its syntax.
Yet ironically, the “official” implementations still aren’t 100% compliant. (libyaml, pyyaml, yaml 1.2 tracker for both)
Why should we be concerned?
Yaml 1.1 → 1.2 had some breaking changes, and more and more libraries are defaulting to 1.2 - after all, it’s been 14 years since release.
The following example is a comparison of what will be parsed in python, using pyyaml (yaml1.1) and ruamel.yaml (yaml1.2):
>>> import yaml
>>> import ruamel.yaml as ryaml
>>> yaml.safe_load("{y: 1, yes: 2, on: 3, true: 4}")
{'y': 1, True: 4}
>>> ryaml.safe_load("{y: 1, yes: 2, on: 3, true: 4}")
{'y': 1, 'yes': 2, 'on': 3, True: 4}
>>> yaml.safe_load("{octal_1_1: 010, octal_1_2: 0o10}")
{'octal_1_1': 8, 'octal_1_2': '0o10'}
>>> ryaml.safe_load("{octal_1_1: 010, octal_1_2: 0o10}")
{'octal_1_1': 10, 'octal_1_2': 8}
>>> yaml.safe_load('0b1')
1
>>> ryaml.safe_load('0b1')
1 # this is a bug, this should be a string, or invalid
As you can see, the parsed output is quite different. While it’s not yet a problem, we should keep in mind that this might cause some trouble in the future.
(We can avoid this using linters, but new users will expect that we’re using the “latest” spec - 1.2)
So what next?
I want to have a discussion on how do we handle this potential problem.
I currently have 2 ideas:
- Call to arms: dedicate some time to contribute to libyaml & pyyaml
It will be slow, but the “preferred open source approach” - Drop libyaml&pyyaml, and use replacements
libfyaml has been suggested in libyaml’s YAML1.2 thread, although I haven’t personally tested.
ruamel.yaml is known to be a nearly drop-in replacement against pyyaml, that supports YAML1.2.
Edit: more examples, and a link to yaml’s changelog