This is an automated email from the ASF dual-hosted git repository. kriskras99 pushed a commit to branch fix/value_to_value in repository https://gitbox.apache.org/repos/asf/avro-rs.git
commit 64085281bf67cbe87aa42f1599acb12067f66cdf Author: Kriskras99 <[email protected]> AuthorDate: Sat Jan 31 10:42:35 2026 +0100 fix: Don't silently truncate numbers larger than `i64::MAX` when converting from JSON --- avro/src/types.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/avro/src/types.rs b/avro/src/types.rs index 0060987..9e4af89 100644 --- a/avro/src/types.rs +++ b/avro/src/types.rs @@ -145,7 +145,7 @@ to_value!(f32, Value::Float); to_value!(f64, Value::Double); to_value!(String, Value::String); to_value!(Vec<u8>, Value::Bytes); -to_value!(uuid::Uuid, Value::Uuid); +to_value!(Uuid, Value::Uuid); to_value!(Decimal, Value::Decimal); to_value!(BigDecimal, Value::BigDecimal); to_value!(Duration, Value::Duration); @@ -283,7 +283,7 @@ impl From<JsonValue> for Value { } } JsonValue::Number(ref n) if n.is_f64() => Value::Double(n.as_f64().unwrap()), - JsonValue::Number(n) => Value::Long(n.as_u64().unwrap() as i64), // TODO: Not so great + JsonValue::Number(n) => panic!("{n:?} does not fit into an Avro long"), JsonValue::String(s) => s.into(), JsonValue::Array(items) => Value::Array(items.into_iter().map(Value::from).collect()), JsonValue::Object(items) => Value::Map( @@ -3240,7 +3240,6 @@ Field with name '"b"' is not a member of the map items"#, assert_eq!(Value::from(json!(1.23)), Value::Double(1.23)); assert_eq!(Value::from(json!(-1.23)), Value::Double(-1.23)); assert_eq!(Value::from(json!(u64::MIN)), Value::Int(u64::MIN as i32)); - assert_eq!(Value::from(json!(u64::MAX)), Value::Long(u64::MAX as i64)); assert_eq!( Value::from(json!("some text")), Value::String("some text".into()) @@ -3500,4 +3499,10 @@ Field with name '"b"' is not a member of the map items"#, Details::ZagI32(_, _) )); } + + #[test] + #[should_panic(expected = "Number(18446744073709551615) does not fit into an Avro long")] + fn avro_rs_xxx_serde_json_number_u64_max() { + let _ = Value::from(json!(u64::MAX)); + } }
