This is an automated email from the ASF dual-hosted git repository. mgrigorov pushed a commit to branch avro-4024-nan-inf-float-defaults in repository https://gitbox.apache.org/repos/asf/avro.git
commit 3704a97cf8f6fe6880d59457fbf57109b8921d12 Author: Martin Tzvetanov Grigorov <[email protected]> AuthorDate: Wed Aug 7 14:15:34 2024 +0300 AVRO-4024: [Rust] Accept only "Nan", "INF", "-INF", "Infinity" and "-Infinity" This is what the Java SDK (via Jackson library) supports (https://github.com/apache/avro/pull/3066). This is what the C# SDK also would support (https://github.com/apache/avro/pull/3070) Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> --- lang/rust/avro/src/types.rs | 8 ++++---- lang/rust/avro/tests/io.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lang/rust/avro/src/types.rs b/lang/rust/avro/src/types.rs index e9d4a31bd..de901df3f 100644 --- a/lang/rust/avro/src/types.rs +++ b/lang/rust/avro/src/types.rs @@ -933,10 +933,10 @@ impl Value { /// IEEE 754 NaN and infinities are not valid JSON numbers. /// So they are represented in JSON as strings. fn parse_special_float(value: &str) -> Option<f32> { - match value.trim().to_ascii_lowercase().as_str() { - "nan" | "+nan" | "-nan" => Some(f32::NAN), - "inf" | "+inf" | "infinity" | "+infinity" => Some(f32::INFINITY), - "-inf" | "-infinity" => Some(f32::NEG_INFINITY), + match value { + "NaN" => Some(f32::NAN), + "INF" | "Infinity" => Some(f32::INFINITY), + "-INF" | "-Infinity" => Some(f32::NEG_INFINITY), _ => None, } } diff --git a/lang/rust/avro/tests/io.rs b/lang/rust/avro/tests/io.rs index 6a59a5071..1937f2bc9 100644 --- a/lang/rust/avro/tests/io.rs +++ b/lang/rust/avro/tests/io.rs @@ -107,14 +107,14 @@ fn default_value_examples() -> &'static Vec<(&'static str, &'static str, Value)> (r#""long""#, "5", Value::Long(5)), (r#""float""#, "1.1", Value::Float(1.1)), (r#""double""#, "1.1", Value::Double(1.1)), - (r#""float""#, r#"" +inf ""#, Value::Float(f32::INFINITY)), + (r#""float""#, r#""INF""#, Value::Float(f32::INFINITY)), ( r#""double""#, r#""-Infinity""#, Value::Double(f64::NEG_INFINITY), ), - (r#""float""#, r#""-NAN""#, Value::Float(f32::NAN)), - (r#""double""#, r#""-NAN""#, Value::Double(f64::NAN)), + (r#""float""#, r#""NaN""#, Value::Float(f32::NAN)), + (r#""double""#, r#""NaN""#, Value::Double(f64::NAN)), ( r#"{"type": "fixed", "name": "F", "size": 2}"#, r#""a""#,
