diff --git a/crates/nu-data/src/base.rs b/crates/nu-data/src/base.rs index 0f020ed3fc..e93111e595 100644 --- a/crates/nu-data/src/base.rs +++ b/crates/nu-data/src/base.rs @@ -164,6 +164,10 @@ pub fn coerce_compare_primitive( (Boolean(left), Boolean(right)) => CompareValues::Booleans(*left, *right), (Boolean(left), Nothing) => CompareValues::Booleans(*left, false), (Nothing, Boolean(right)) => CompareValues::Booleans(false, *right), + (String(left), Nothing) => CompareValues::String(left.clone(), std::string::String::new()), + (Nothing, String(right)) => { + CompareValues::String(std::string::String::new(), right.clone()) + } (FilePath(left), String(right)) => { CompareValues::String(left.as_path().display().to_string(), right.clone()) } diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 0e923977d1..70162924fa 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -1083,6 +1083,30 @@ fn manysubcommand() { assert_eq!(actual.out, "localhost loaded"); } +#[test] +fn nothing_string_1() { + let actual = nu!( + cwd: ".", pipeline( + r#" + $nothing == "foo" + "#) + ); + + assert_eq!(actual.out, "false"); +} + +#[test] +fn nothing_string_2() { + let actual = nu!( + cwd: ".", pipeline( + r#" + "" == $nothing + "#) + ); + + assert_eq!(actual.out, "true"); +} + mod parse { use nu_test_support::nu;