From ad296b485334a90a7a8e57921889eec1b90d9003 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Wed, 28 Oct 2026 23:20:56 +0000 Subject: [PATCH] Validate fractionals --- src/types/number_or_text.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/types/number_or_text.rs b/src/types/number_or_text.rs index 63b7a18..c9412d8 100644 --- a/src/types/number_or_text.rs +++ b/src/types/number_or_text.rs @@ -37,8 +37,14 @@ impl TryFrom for NumberOrText { )); } + if num.fract() != 0.0 { + return Err(DeserialisationError::new( + "Floating-point number must be an integer", + )); + } + #[allow(clippy::cast_possible_truncation)] - return Ok(NumberOrText::Number(num.round() as i64)); + return Ok(NumberOrText::Number(num as i64)); } if let Ok(text) = value.try_into() { @@ -110,10 +116,3 @@ impl std::fmt::Display for DeserialisationError { #[cfg(feature = "wasm")] impl std::error::Error for DeserialisationError {} - -#[cfg(feature = "wasm")] -impl From for JsValue { - fn from(error: DeserialisationError) -> Self { - JsValue::from_str(&error.message) - } -}