Skip to content

Commit 3704a97

Browse files
committed
AVRO-4024: [Rust] Accept only "Nan", "INF", "-INF", "Infinity" and "-Infinity"
This is what the Java SDK (via Jackson library) supports (#3066). This is what the C# SDK also would support (#3070) Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
1 parent 0af4e1b commit 3704a97

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

lang/rust/avro/src/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -933,10 +933,10 @@ impl Value {
933933
/// IEEE 754 NaN and infinities are not valid JSON numbers.
934934
/// So they are represented in JSON as strings.
935935
fn parse_special_float(value: &str) -> Option<f32> {
936-
match value.trim().to_ascii_lowercase().as_str() {
937-
"nan" | "+nan" | "-nan" => Some(f32::NAN),
938-
"inf" | "+inf" | "infinity" | "+infinity" => Some(f32::INFINITY),
939-
"-inf" | "-infinity" => Some(f32::NEG_INFINITY),
936+
match value {
937+
"NaN" => Some(f32::NAN),
938+
"INF" | "Infinity" => Some(f32::INFINITY),
939+
"-INF" | "-Infinity" => Some(f32::NEG_INFINITY),
940940
_ => None,
941941
}
942942
}

lang/rust/avro/tests/io.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ fn default_value_examples() -> &'static Vec<(&'static str, &'static str, Value)>
107107
(r#""long""#, "5", Value::Long(5)),
108108
(r#""float""#, "1.1", Value::Float(1.1)),
109109
(r#""double""#, "1.1", Value::Double(1.1)),
110-
(r#""float""#, r#"" +inf ""#, Value::Float(f32::INFINITY)),
110+
(r#""float""#, r#""INF""#, Value::Float(f32::INFINITY)),
111111
(
112112
r#""double""#,
113113
r#""-Infinity""#,
114114
Value::Double(f64::NEG_INFINITY),
115115
),
116-
(r#""float""#, r#""-NAN""#, Value::Float(f32::NAN)),
117-
(r#""double""#, r#""-NAN""#, Value::Double(f64::NAN)),
116+
(r#""float""#, r#""NaN""#, Value::Float(f32::NAN)),
117+
(r#""double""#, r#""NaN""#, Value::Double(f64::NAN)),
118118
(
119119
r#"{"type": "fixed", "name": "F", "size": 2}"#,
120120
r#""a""#,

0 commit comments

Comments
 (0)