-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Float parsing is unnecessarily restrictive #290
Comments
@rogpeppe I think that's reasonable from our use case. A git commit ID shouldn't have those characters :) |
The current version seems to fail on "0." which should definitely be accepted.
|
Why do you say that it should definitely be accepted? That string doesn't match the regular expression provided in the standard, which includes mandatory digit after the decimal point. |
That part of the regexp is We have a tool that write yaml and we now patched it as a hotfix. |
@ensonic I think you're actually reading the regexp wrong. It specifically has an unqualified Here's a regexp tester showing a negative match for Note that I put a 0 at the beginning of the regexp to allow us to test with |
On reading the spec a bit more closely, the regexp currently used is the canonical pattern for numbers; the actual regexp is specified in section 10.3.2 and is |
He, no worries. My brain actually misinterpreted the regexp above. But indeed on yaml.org (http://yaml.org/type/float.html) they list a different regexp. In any case, just wanted to let you know that we're not blocked. |
This issue seems somewhat theoretical right now. If someone has actual issues with the current behavior, please let us know and we'll look into it. |
Actually, reopening. Went looking further, and the changes in PR #171, and the tests added there, indeed disagree with the specification. So this is not just unnecessarily restrictive, it's plain wrong if we intend to implement version 1.2 of the spec. Will look further into that for v3. |
FWIW PR #171 (commit 4c78c97) seems to have caused breakage beyond the desired fix issue. This was the code I used to bisect, FWIW:
|
Previously it looked like docker resources were supported but they didn't work because the filename parameter was mandatory. Also make the tests pass on yaml.v2 tip; see go-yaml/yaml#290.
Previously it looked like docker resources were supported but they didn't work because the filename parameter was mandatory. Also make the tests pass on yaml.v2 tip; see go-yaml/yaml#290.
This hit us as well - we can no longer use e.g. 10e9 as a shorthand for 10 GB, and 10000000000 is not as readable. |
Fixed in 7b8349a. Sorry for the trouble. |
Right, but that is for Yaml 1.1, whereas the Regarding decimal and plus/minus characters,
Right. However, since the decimal and the I feel like this may be a weakness in the YAML 1.2 spec under 10.1.1.3 Generic String where it describes the Canonical Form glibly as "The obvious." I am not very familiar with how the spec works, but it seems to me that if there is no clearly described canonical form for strings, serialization tools are liable to produce output (like the example above) which does not produce accurate round-trip ser/deser. I plan to ask what they think about that on the YAML mailing list. |
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 <[email protected]>
PR #171 restricted the possible float syntax, but it's not clear that it was the right thing to do.
The YAML spec itself provides a regexp for floats (
-?[1-9](\.[0-9]*[1-9])?(e[-+][1-9][0-9]*)?
) that is cast into doubt by the example immediately following (2.3e4
) which is not matched by the regexp.Also, JSON allows floats of the form
2e5
and YAML is supposed to be able to read JSON.As it seems other implementations treat
[0-9]+e[0-9]+
as a string, perhaps we should do that too, despite JSON-incompatibility, but treat it as a float if there's a decimal point in the mantissa or a + or - sign before the exponent.The text was updated successfully, but these errors were encountered: