From 7e5217babe56fd3177b5117e6f1d5ca6086e2aa0 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Fri, 6 Dec 2024 14:02:51 -0500 Subject: [PATCH 1/2] Revert "fix(convert): return error when conversion exceeds f64 bounds (#1108)" This reverts commit 2ee31a41923b30c9ea1216ca3971ff41fc3f2fd0. --- src/compiler/conversion/mod.rs | 5 ---- src/compiler/conversion/tests/mod.rs | 34 +--------------------------- 2 files changed, 1 insertion(+), 38 deletions(-) diff --git a/src/compiler/conversion/mod.rs b/src/compiler/conversion/mod.rs index e22d14d5af..3abfd7db74 100644 --- a/src/compiler/conversion/mod.rs +++ b/src/compiler/conversion/mod.rs @@ -159,11 +159,6 @@ impl Conversion { let parsed = s .parse::() .with_context(|_| FloatParseSnafu { s: s.clone() })?; - if !parsed.is_normal() { - return Err(Error::NanFloat { - s: format!("Invalid float \"{s}\": not a normal f64 number"), - }); - } let f = NotNan::new(parsed).map_err(|_| Error::NanFloat { s: s.to_string() })?; f.into() } diff --git a/src/compiler/conversion/tests/mod.rs b/src/compiler/conversion/tests/mod.rs index 3e0780662f..958c9dc77c 100644 --- a/src/compiler/conversion/tests/mod.rs +++ b/src/compiler/conversion/tests/mod.rs @@ -2,8 +2,7 @@ use bytes::Bytes; use chrono::{DateTime, Utc}; use ordered_float::NotNan; -use crate::compiler::conversion::{parse_bool, Conversion, Error}; -use crate::compiler::TimeZone; +use crate::compiler::conversion::parse_bool; #[cfg(unix)] // see https://github.com/vectordotdev/vector/issues/1201 mod unix; @@ -92,34 +91,3 @@ fn parse_bool_errors() { assert!(parse_bool("yes or no").is_err()); assert!(parse_bool("123.4").is_err()); } - -fn convert_float(input: impl ToString) -> Result { - let input = input.to_string(); - let converter = Conversion::parse("float", TimeZone::Local).expect("float conversion"); - converter.convert::(input.into()) -} - -#[test] -fn convert_float_ok() { - let max_float = format!("17976931348623157{}", "0".repeat(292)); - let min_float = format!("-{max_float}"); - - assert_eq!(convert_float(max_float), Ok(StubValue::Float(f64::MAX))); - assert_eq!(convert_float("1"), Ok(StubValue::Float(1.0))); - assert_eq!(convert_float("1.23"), Ok(StubValue::Float(1.23))); - assert_eq!(convert_float("-1"), Ok(StubValue::Float(-1.0))); - assert_eq!(convert_float("-1.23"), Ok(StubValue::Float(-1.23))); - assert_eq!(convert_float(min_float), Ok(StubValue::Float(f64::MIN))); -} - -#[test] -fn convert_float_errors() { - let exceeds_max_float = format!("17976931348623159{}", "0".repeat(292)); // last number inc by 2 - let exceeds_min_float = format!("-{exceeds_max_float}"); - - assert!(convert_float("abc").is_err()); - assert!(convert_float("1.23.4").is_err()); - assert!(convert_float(exceeds_max_float).is_err()); - assert!(convert_float(exceeds_min_float).is_err()); - assert!(convert_float("0.0").is_err()); -} From 8d9fa702955f704ffec56f37a126ac707efce1b6 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Fri, 6 Dec 2024 15:31:27 -0500 Subject: [PATCH 2/2] add changelog --- changelog.d/1179.fix.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog.d/1179.fix.md diff --git a/changelog.d/1179.fix.md b/changelog.d/1179.fix.md new file mode 100644 index 0000000000..285b4cad5c --- /dev/null +++ b/changelog.d/1179.fix.md @@ -0,0 +1,2 @@ +Reverted `to_float` [change](https://github.com/vectordotdev/vrl/pull/1107) because the new logic is too restrictive +e.g. attempting to convert "0" returns an error.