Closed as not planned
Description
I'm using pyyaml version 6.0.1 and I've discovered that strings that end in '8' and '9' that are prefixed with at least one '0' are treated differently than strings ending with any other digit. This is problematic in that other interpreters (namely yaml-cpp
) then fail to properly interpret the data as a string.
After diving into the resolver.py
code, it looks like this is because of this regex, which matches '0007' but does not match '0008' or '0009'.
Resolver.add_implicit_resolver(
'tag:yaml.org,2002:int',
re.compile(r'''^(?:[-+]?0b[0-1_]+
|[-+]?0[0-7_]+
|[-+]?(?:0|[1-9][0-9_]*)
|[-+]?0x[0-9a-fA-F_]+
|[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$''', re.X),
list('-+0123456789'))
Here is a minimal example:
import yaml
fields = {'0007': {'key': 'val'}, '0008': {'key': 'val'}, '0009': {'key': 'val'}, '0010': {'key': 'val'}}
with open('tmp.yaml', 'w') as stream:
yaml.safe_dump(fields, stream)
The resulting file looks like:
'0007':
key: val
0008:
key: val
0009:
key: val
'0010':
key: val
Metadata
Metadata
Assignees
Labels
No labels