yeison / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
0 stars 0 forks source link

scientific notation resolver bug #130

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. insert the following yaml document into http://instantyaml.appspot.com/

a: 8e-06
b: 8.e-06

What is the expected output? What do you see instead?

8e-06 is parsed as a string, contrary to yaml 1.2 (it was somewhat unclear for 
yaml 1.1)
Please see Jesse Beder's response in: 
http://stackoverflow.com/questions/6769292/yaml-scientific-notation-syntax

yaml 1.2 uses the regexp:
[-+]? ( \. [0-9]+ | [0-9]+ ( \. [0-9]* )? ) ( [eE] [-+]? [0-9]+ )?

while it's possible 1.1 may be:
[-+]?([0-9][0-9_]*)?\.[0-9.]*([eE][-+][0-9]+)?

which requires the decimal.

I was able to work around this in my project, but the base of the problem was 
that I was trying to use a yaml output which used yaml-cpp which does 1.2 and 
then trying to use snakeyaml to input it, and it was failing to parse the 
string with certain numbers that happened very infrequently.

Original issue reported on code.google.com by xan...@gmail.com on 23 Jul 2011 at 5:44

GoogleCodeExporter commented 9 years ago
Indeed, it looks like a bug in the YAML 1.1 specification. Jesse Beder gave a 
very helpful answer. It is really useful.
I see now problem areas in the YAML 1.2 specification. For instance if a value 
starts with '+' then a JSON parser will create a string while the YAML 1.2 
parser should create a float. Since YAML 1.2 is a superset of JSON it does not 
lead to inconsistency but it will cause some misunderstanding.
I do not see a problem to fix this in the coming 1.9 release.

Original comment by py4fun@gmail.com on 25 Jul 2011 at 9:00

GoogleCodeExporter commented 9 years ago
a few questions on the way to implement the fix:
1) what should be the class of the result '8e+08' ? Double ? Integer (or 
BigInteger if Integer or Long do not fit). I think 'e' must always require a 
Double.
2) normal integers match the regular expression for floats in the YAML 1.2 
specification. It means that integers must be matched always first. I think 
they shall fix the regular expression for floats in YAML 1.2

Original comment by py4fun@gmail.com on 25 Jul 2011 at 9:28

GoogleCodeExporter commented 9 years ago
Fixed. The fix will be delivered in version 1.9

Wiki updated:
http://code.google.com/p/snakeyaml/wiki/Documentation#Deviation_from_PyYAML

Original comment by py4fun@gmail.com on 26 Jul 2011 at 2:00