fjoppe / Legivel

F# Yaml 1.2 parser
https://fjoppe.github.io/Legivel
The Unlicense
60 stars 5 forks source link

Fail to deserialize NaN and Infinite #32

Closed johannesvp closed 4 years ago

johannesvp commented 4 years ago

Description

I cannot deserialize an infinite floating point number in yaml to a float. Ditto for 'not a number'.

Expected behavior

Deserialize<float> "1.23" = 1.23 Deserialize<float> "NaN" = nan Deserialize<float> "nan" = nan Deserialize<float> ".nan" = nan

Actual behavior

Deserialize<float> "1.23" = 1.23 Deserialize<float> "NaN" = "Incorrect format: 'NaN', for tag: tag:yaml.org,2002:float" Deserialize<float> "nan" = "Incorrect format: 'nan', for tag: tag:yaml.org,2002:float" Deserialize<float> ".nan" = System.FormatException: Input string was not in a correct format.

Known workarounds

No workarounds. No value is accepted for nan/infinite in yaml.

Related information

src/Legivel.Mapper/Customization.fs: let value = YamlExtended.FloatGlobalTag.ToCanonical s |> Option.get Double.Parse(value, CultureInfo.InvariantCulture) |> box)

It looks like the ToCanonical always returns Some ".nan" for "not a number". This is not the correct input for Double.Parse. Similar problem for infinite.

fjoppe commented 4 years ago

This looks like an issue. I will look into it.

fjoppe commented 4 years ago

Note:

Deserialize "NaN" = "Incorrect format: 'NaN', for tag: tag:yaml.org,2002:float"

This is expected behavior. Both nan and inf need to preceed with a dot (see regexp part).

fjoppe commented 4 years ago

Fixed in 0.4.5

https://www.nuget.org/packages/Legivel/0.4.5

johannesvp commented 4 years ago

Tested with ".nan", ".inf", "+.inf" and "-.inf". All working fine.

Thank you very much for the fix. I really appreciate that you fixed it this fast.