C based SafeLoader does not respect yaml version directive
C version of reader, parser and emitter for ruamel.yaml
Brought to you by:
anthon
Hi
The C based SafeLoader does not respect the yaml version directive, it always handles the document as yaml 1.2 without a warning. It still parses the version in a way, because it fails with an assertion if the directive is specified with a version different than 1.1 or 1.2.
This little script
from ruamel.yaml import YAML
document = """%YAML 1.1
---
- 010
- yes
"""
print("round-trip")
rt_yaml = YAML()
print(rt_yaml.load(document))
print("\nsafe pure")
safe_yaml_pure = YAML(typ="safe", pure=True)
print(safe_yaml_pure.load(document))
print("\nsafe")
safe_yaml = YAML(typ="safe")
print(safe_yaml.load(document))
print("\nsafe with version set")
safe_yaml_version = YAML(typ="safe")
safe_yaml_version.version = (1, 1)
print(safe_yaml_version.load(document))
produces the following output
round-trip
[8, True]
safe pure
[8, True]
safe
[10, 'yes']
safe with version set
[8, True]
Kind regards,
Adrian
Ticket moved from /p/ruamel-yaml/tickets/505/