From c078234f65aec631d9ebae1ac5fd5e77f2172f0e Mon Sep 17 00:00:00 2001 From: Javier Ciberman Mora Date: Thu, 30 Mar 2023 00:49:32 -0300 Subject: [PATCH] Fixes #792 parsing bug for floats with non english culture Adds `YamlFormatter.NumberFormat` in `Parse` methods in `ScalarNodeDeserializer.AttemptUnknownTypeDeserialization`. This caused tests to fail in non english culture (Tested with "es-AR") --- .../NodeDeserializers/ScalarNodeDeserializer.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs b/YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs index 7395fd37..8f323821 100644 --- a/YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs +++ b/YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs @@ -364,13 +364,13 @@ private static object CastInteger(ulong number, TypeCode typeCode) } else if (Regex.IsMatch(v, @"[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?")) //regular number { - if (TryAndSwallow(() => byte.Parse(v), out result)) { } - else if (TryAndSwallow(() => short.Parse(v), out result)) { } - else if (TryAndSwallow(() => int.Parse(v), out result)) { } - else if (TryAndSwallow(() => long.Parse(v), out result)) { } - else if (TryAndSwallow(() => ulong.Parse(v), out result)) { } - else if (TryAndSwallow(() => float.Parse(v), out result)) { } - else if (TryAndSwallow(() => double.Parse(v), out result)) { } + if (TryAndSwallow(() => byte.Parse(v, YamlFormatter.NumberFormat), out result)) { } + else if (TryAndSwallow(() => short.Parse(v, YamlFormatter.NumberFormat), out result)) { } + else if (TryAndSwallow(() => int.Parse(v, YamlFormatter.NumberFormat), out result)) { } + else if (TryAndSwallow(() => long.Parse(v, YamlFormatter.NumberFormat), out result)) { } + else if (TryAndSwallow(() => ulong.Parse(v, YamlFormatter.NumberFormat), out result)) { } + else if (TryAndSwallow(() => float.Parse(v, YamlFormatter.NumberFormat), out result)) { } + else if (TryAndSwallow(() => double.Parse(v, YamlFormatter.NumberFormat), out result)) { } else { //we couldn't parse it, default to string, It's probably too big