From 4d920051258b8ed4f72d193514fdaee97578b5a3 Mon Sep 17 00:00:00 2001 From: Dave MacLeod <56599343+Dhghomon@users.noreply.github.com> Date: Mon, 16 Sep 2024 17:46:31 +0900 Subject: [PATCH] Remove eager parsing of `"false"` truthiness (#4775) Co-authored-by: Tobie Morgan Hitchcock --- core/src/sql/value/value.rs | 4 ++-- sdk/tests/function.rs | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core/src/sql/value/value.rs b/core/src/sql/value/value.rs index af05eeed..c51118ef 100644 --- a/core/src/sql/value/value.rs +++ b/core/src/sql/value/value.rs @@ -961,7 +961,7 @@ impl Value { Value::Geometry(_) => true, Value::Array(v) => !v.is_empty(), Value::Object(v) => !v.is_empty(), - Value::Strand(v) => !v.is_empty() && !v.eq_ignore_ascii_case("false"), + Value::Strand(v) => !v.is_empty(), Value::Number(v) => v.is_truthy(), Value::Duration(v) => v.as_nanos() > 0, Value::Datetime(v) => v.timestamp() > 0, @@ -3164,7 +3164,7 @@ mod tests { assert!(Value::from(1.1).is_truthy()); assert!(Value::from(-1.1).is_truthy()); assert!(Value::from("true").is_truthy()); - assert!(!Value::from("false").is_truthy()); + assert!(Value::from("false").is_truthy()); assert!(Value::from("falsey").is_truthy()); assert!(Value::from("something").is_truthy()); assert!(Value::from(Uuid::new()).is_truthy()); diff --git a/sdk/tests/function.rs b/sdk/tests/function.rs index 258f0571..6ce3e09f 100644 --- a/sdk/tests/function.rs +++ b/sdk/tests/function.rs @@ -599,10 +599,11 @@ async fn function_array_len() -> Result<(), Error> { #[tokio::test] async fn function_array_logical_and() -> Result<(), Error> { test_queries( - r#"RETURN array::logical_and([true, false, true, false], [true, true, false, false]); -RETURN array::logical_and([1, 0, 1, 0], ["true", "true", "false", "false"]); -RETURN array::logical_and([0, 1], []);"#, - &["[true, false, false, false]", r#"[1, 0, "false", 0]"#, "[0, null]"], + r#" + RETURN array::logical_and([true, false, true, false], [true, true, false, false]); + RETURN array::logical_and([1, 0, 1, 0], [true, true, false, false]); + RETURN array::logical_and([0, 1], []);"#, + &["[true, false, false, false]", r#"[1, 0, false, 0]"#, "[0, null]"], ) .await?; Ok(()) @@ -611,10 +612,11 @@ RETURN array::logical_and([0, 1], []);"#, #[tokio::test] async fn function_array_logical_or() -> Result<(), Error> { test_queries( - r#"RETURN array::logical_or([true, false, true, false], [true, true, false, false]); -RETURN array::logical_or([1, 0, 1, 0], ["true", "true", "false", "false"]); -RETURN array::logical_or([0, 1], []);"#, - &["[true, true, true, false]", r#"[1, "true", 1, 0]"#, "[0, 1]"], + r#" + RETURN array::logical_or([true, false, true, false], [true, true, false, false]); + RETURN array::logical_or([1, 0, 1, 0], [true, true, false, false]); + RETURN array::logical_or([0, 1], []);"#, + &["[true, true, true, false]", r#"[1, true, 1, 0]"#, "[0, 1]"], ) .await?; Ok(()) @@ -623,10 +625,11 @@ RETURN array::logical_or([0, 1], []);"#, #[tokio::test] async fn function_array_logical_xor() -> Result<(), Error> { test_queries( - r#"RETURN array::logical_xor([true, false, true, false], [true, true, false, false]); -RETURN array::logical_xor([1, 0, 1, 0], ["true", "true", "false", "false"]); -RETURN array::logical_xor([0, 1], []);"#, - &["[false, true, true, false]", r#"[false, "true", 1, 0]"#, "[0, 1]"], + r#" + RETURN array::logical_xor([true, false, true, false], [true, true, false, false]); + RETURN array::logical_xor([1, 0, 1, 0], [true, true, false, false]); + RETURN array::logical_xor([0, 1], []);"#, + &["[false, true, true, false]", r#"[false, true, 1, 0]"#, "[0, 1]"], ) .await?; Ok(())