Prechádzať zdrojové kódy

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.
Gustavo Niemeyer 7 rokov pred
rodič
commit
112d6e722c
2 zmenil súbory, kde vykonal 4 pridanie a 4 odobranie
  1. 3 3
      decode_test.go
  2. 1 1
      resolve.go

+ 3 - 3
decode_test.go

@@ -670,13 +670,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
 	{

+ 1 - 1
resolve.go

@@ -77,7 +77,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) {