Skip to content

Commit

Permalink
Fix float resolver for '.'
Browse files Browse the repository at this point in the history
A single dot matches the YAML 1.1 int regex.
This should probably be resolved as '0.0'.

This commit fixes the regex to make digits before the dot optional.
  • Loading branch information
perlpunk committed Feb 5, 2021
1 parent 8f85b31 commit fbd7221
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib3/yaml/constructor.py
Expand Up @@ -279,6 +279,8 @@ def construct_yaml_float(self, node):
return sign*self.inf_value
elif value == '.nan':
return self.nan_value
elif value == '.':
return 0.0
elif ':' in value:
digits = [float(part) for part in value.split(':')]
digits.reverse()
Expand Down
2 changes: 1 addition & 1 deletion lib3/yaml/resolver.py
Expand Up @@ -176,7 +176,7 @@ class Resolver(BaseResolver):

Resolver.add_implicit_resolver(
'tag:yaml.org,2002:float',
re.compile(r'''^(?:[-+]?(?:[0-9][0-9_]*)\.[0-9_]*(?:[eE][-+][0-9]+)?
re.compile(r'''^(?:[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*(?:[eE][-+][0-9]+)?
|\.[0-9_]+(?:[eE][-+][0-9]+)?
|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*
|[-+]?\.(?:inf|Inf|INF)
Expand Down
1 change: 0 additions & 1 deletion tests/data/yaml11.schema-skip
@@ -1,7 +1,6 @@
load: {
'Y': 1, 'y': 1, 'N': 1, 'n': 1,
'!!bool Y': 1, '!!bool N': 1, '!!bool n': 1, '!!bool y': 1,
'!!float .': 1, '!!float ._', '!!str .', '.', '._',
}
dump: {
'!!str N': 1, '!!str Y': 1, '!!str n': 1, '!!str y': 1,
Expand Down

0 comments on commit fbd7221

Please sign in to comment.