fix default after an empty where (#10240)

should close https://github.com/nushell/nushell/issues/10237

# Description
this is @fdncred's findings 😋 
i just made the PR 😌 

# User-Facing Changes
```nushell
[a b] | where $it == 'c' | last | default 'd'
```
now works and gives `d`


# Tests + Formatting
adds a new `default_after_empty_filter` test.

# After Submitting
This commit is contained in:
Antoine Stevan 2023-09-06 10:39:35 +02:00 committed by GitHub
parent 456e2a8ee3
commit f433b3102f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -2,7 +2,8 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned,
SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -114,6 +115,8 @@ fn default(
}, },
ctrlc, ctrlc,
) )
} else if input.is_nothing() {
Ok(value.into_pipeline_data())
} else { } else {
input.map( input.map(
move |item| match item { move |item| match item {

View File

@ -33,3 +33,10 @@ fn adds_row_data_if_column_missing() {
assert_eq!(actual.out, "2"); assert_eq!(actual.out, "2");
}); });
} }
#[test]
fn default_after_empty_filter() {
let actual = nu!("[a b] | where $it == 'c' | last | default 'd'");
assert_eq!(actual.out, "d");
}