Update the yamlStyleFloat regex for special case. #241

Open
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants

Fixes #157 by updating the regex for float matching.

Instead of allowing mantissa to be any 0-9 sequence, this change means it must be either 0, or not start with a zero.

@@ -81,7 +81,7 @@ func resolvableTag(tag string) bool {
return false
}
-var yamlStyleFloat = regexp.MustCompile(`^[-+]?[0-9]*\.?[0-9]+([eE][-+][0-9]+)?$`)
+var yamlStyleFloat = regexp.MustCompile(`^[-+]?(0|[1-9][0-9]*)?(\.[0-9]+)?([eE][-+][0-9]+)?$`)
@gabriel-samfira

gabriel-samfira May 18, 2017

Shouldn't this be:

// the sign of what follows after "[eE]" should be optional. 
var yamlStyleFloat = regexp.MustCompile(`^[-+]?(0|[1-9][0-9]*)?(\.[0-9]+)?([eE][-+]?[0-9]+)?$`)

to allow:

floats := []string{
   "2.2e11",
   "2.2e+11", // same as above, but with an explicit sign
   "2.2e-11",
}

?

@howbazaar

howbazaar May 18, 2017

Well the spec says that all exponents must have explicit sign.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment