Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 7b8349a

Browse files
committed
Parse floats correctly and fix mistake from #171
The regular expression is copy & pasted form the one in the spec. The change suggested in #171 and integrated was improper. Closes #290
1 parent 51d6538 commit 7b8349a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

decode_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,13 +691,13 @@ var unmarshalTests = []struct {
691691
M{"ñoño": "very yes 🟔"},
692692
},
693693

694-
// YAML Float regex shouldn't match this
694+
// This *is* in fact a float number, per the spec. #171 was a mistake.
695695
{
696696
"a: 123456e1\n",
697-
M{"a": "123456e1"},
697+
M{"a": 123456e1},
698698
}, {
699699
"a: 123456E1\n",
700-
M{"a": "123456E1"},
700+
M{"a": 123456E1},
701701
},
702702
// yaml-test-suite 3GZX: Spec Example 7.1. Alias Nodes
703703
{

resolve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func resolvableTag(tag string) bool {
8181
return false
8282
}
8383

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

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

0 commit comments

Comments
 (0)