handle empty pipeline while parsing let (fix Issue10083) (#10116)

- fixes #10083 

# Description

nushell crashes in the following 2 condition:

- `let a = {}` , then delete `{`
- `let a = | {}`, then delete `{`

When delete `{` the pipeline becomes empty but current `nu-parser`
assume they are non-empty. This pr adds extra empty check to avoid
crash.


Co-authored-by: Horasal <horsal@horsal.dev>
This commit is contained in:
Horasal
2023-08-28 20:38:11 +09:00
committed by GitHub
parent 38f454d5ab
commit 1f06f8405c
2 changed files with 26 additions and 7 deletions

View File

@ -1007,6 +1007,18 @@ mod string {
}
}
#[rstest]
#[case(b"let a = }")]
#[case(b"mut a = }")]
#[case(b"let a = | }")]
#[case(b"mut a = | }")]
fn test_semi_open_brace(#[case] phrase: &[u8]) {
let engine_state = EngineState::new();
let mut working_set = StateWorkingSet::new(&engine_state);
// this should not panic
let _block = parse(&mut working_set, None, phrase, true);
}
mod range {
use super::*;
use nu_protocol::ast::{RangeInclusion, RangeOperator};