Remove eager parsing of "false" truthiness (#4775)

Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
Dave MacLeod 2024-09-16 17:46:31 +09:00 committed by GitHub
parent 065ac9cd5a
commit 4d92005125
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 14 deletions

View file

@ -961,7 +961,7 @@ impl Value {
Value::Geometry(_) => true, Value::Geometry(_) => true,
Value::Array(v) => !v.is_empty(), Value::Array(v) => !v.is_empty(),
Value::Object(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::Number(v) => v.is_truthy(),
Value::Duration(v) => v.as_nanos() > 0, Value::Duration(v) => v.as_nanos() > 0,
Value::Datetime(v) => v.timestamp() > 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(-1.1).is_truthy()); assert!(Value::from(-1.1).is_truthy());
assert!(Value::from("true").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("falsey").is_truthy());
assert!(Value::from("something").is_truthy()); assert!(Value::from("something").is_truthy());
assert!(Value::from(Uuid::new()).is_truthy()); assert!(Value::from(Uuid::new()).is_truthy());

View file

@ -599,10 +599,11 @@ async fn function_array_len() -> Result<(), Error> {
#[tokio::test] #[tokio::test]
async fn function_array_logical_and() -> Result<(), Error> { async fn function_array_logical_and() -> Result<(), Error> {
test_queries( test_queries(
r#"RETURN array::logical_and([true, false, true, false], [true, true, false, false]); r#"
RETURN array::logical_and([1, 0, 1, 0], ["true", "true", "false", "false"]); RETURN array::logical_and([true, false, true, false], [true, true, false, false]);
RETURN array::logical_and([0, 1], []);"#, RETURN array::logical_and([1, 0, 1, 0], [true, true, false, false]);
&["[true, false, false, false]", r#"[1, 0, "false", 0]"#, "[0, null]"], RETURN array::logical_and([0, 1], []);"#,
&["[true, false, false, false]", r#"[1, 0, false, 0]"#, "[0, null]"],
) )
.await?; .await?;
Ok(()) Ok(())
@ -611,10 +612,11 @@ RETURN array::logical_and([0, 1], []);"#,
#[tokio::test] #[tokio::test]
async fn function_array_logical_or() -> Result<(), Error> { async fn function_array_logical_or() -> Result<(), Error> {
test_queries( test_queries(
r#"RETURN array::logical_or([true, false, true, false], [true, true, false, false]); r#"
RETURN array::logical_or([1, 0, 1, 0], ["true", "true", "false", "false"]); RETURN array::logical_or([true, false, true, false], [true, true, false, false]);
RETURN array::logical_or([0, 1], []);"#, RETURN array::logical_or([1, 0, 1, 0], [true, true, false, false]);
&["[true, true, true, false]", r#"[1, "true", 1, 0]"#, "[0, 1]"], RETURN array::logical_or([0, 1], []);"#,
&["[true, true, true, false]", r#"[1, true, 1, 0]"#, "[0, 1]"],
) )
.await?; .await?;
Ok(()) Ok(())
@ -623,10 +625,11 @@ RETURN array::logical_or([0, 1], []);"#,
#[tokio::test] #[tokio::test]
async fn function_array_logical_xor() -> Result<(), Error> { async fn function_array_logical_xor() -> Result<(), Error> {
test_queries( test_queries(
r#"RETURN array::logical_xor([true, false, true, false], [true, true, false, false]); r#"
RETURN array::logical_xor([1, 0, 1, 0], ["true", "true", "false", "false"]); RETURN array::logical_xor([true, false, true, false], [true, true, false, false]);
RETURN array::logical_xor([0, 1], []);"#, RETURN array::logical_xor([1, 0, 1, 0], [true, true, false, false]);
&["[false, true, true, false]", r#"[false, "true", 1, 0]"#, "[0, 1]"], RETURN array::logical_xor([0, 1], []);"#,
&["[false, true, true, false]", r#"[false, true, 1, 0]"#, "[0, 1]"],
) )
.await?; .await?;
Ok(()) Ok(())