Skip to content

Commit

Permalink
Parse floats correctly and fix mistake from go-yaml/yaml#171
Browse files Browse the repository at this point in the history
The regular expression is copy & pasted form the one in the spec.
The change suggested in go-yaml/yaml#171 and integrated was improper.

Closes go-yaml/yaml#290

(cherry-pick of go-yaml/yaml@7b8349a)

Signed-off-by: John Ryan <jtigger@infosysengr.com>
  • Loading branch information
niemeyer authored and jtigger committed Sep 4, 2021
1 parent 6af0e3a commit ee03eb5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pkg/yamlmeta/internal/yaml.v2/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,13 +694,13 @@ var unmarshalTests = []struct {
M{"ñoño": "very yes 🟔"},
},

// YAML Float regex shouldn't match this
// This *is* in fact a float number, per the spec. #171 was a mistake.
{
"a: 123456e1\n",
M{"a": "123456e1"},
M{"a": 123456e1},
}, {
"a: 123456E1\n",
M{"a": "123456E1"},
M{"a": 123456E1},
},
// yaml-test-suite 3GZX: Spec Example 7.1. Alias Nodes
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/yamlmeta/internal/yaml.v2/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func resolvableTag(tag string) bool {
return false
}

var yamlStyleFloat = regexp.MustCompile(`^[-+]?[0-9]*\.?[0-9]+([eE][-+][0-9]+)?$`)
var yamlStyleFloat = regexp.MustCompile(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`)

func resolve(tag string, in string) (rtag string, out interface{}) {
if !resolvableTag(tag) {
Expand Down

0 comments on commit ee03eb5

Please sign in to comment.