mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Fix panic when redirecting nothing (#12970)
# Description Fixes #12969 where the parser can panic if a redirection is applied to nothing / an empty command. # Tests + Formatting Added a test.
This commit is contained in:
@ -727,6 +727,45 @@ fn test_redirection_with_letmut(#[case] phase: &[u8]) {
|
||||
));
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(b"o>")]
|
||||
#[case(b"o>>")]
|
||||
#[case(b"e>")]
|
||||
#[case(b"e>>")]
|
||||
#[case(b"o+e>")]
|
||||
#[case(b"o+e>>")]
|
||||
#[case(b"e>|")]
|
||||
#[case(b"o+e>|")]
|
||||
#[case(b"|o>")]
|
||||
#[case(b"|o>>")]
|
||||
#[case(b"|e>")]
|
||||
#[case(b"|e>>")]
|
||||
#[case(b"|o+e>")]
|
||||
#[case(b"|o+e>>")]
|
||||
#[case(b"|e>|")]
|
||||
#[case(b"|o+e>|")]
|
||||
#[case(b"e> file")]
|
||||
#[case(b"e>> file")]
|
||||
#[case(b"o> file")]
|
||||
#[case(b"o>> file")]
|
||||
#[case(b"o+e> file")]
|
||||
#[case(b"o+e>> file")]
|
||||
#[case(b"|e> file")]
|
||||
#[case(b"|e>> file")]
|
||||
#[case(b"|o> file")]
|
||||
#[case(b"|o>> file")]
|
||||
#[case(b"|o+e> file")]
|
||||
#[case(b"|o+e>> file")]
|
||||
fn test_redirecting_nothing(#[case] text: &[u8]) {
|
||||
let engine_state = EngineState::new();
|
||||
let mut working_set = StateWorkingSet::new(&engine_state);
|
||||
let _ = parse(&mut working_set, None, text, true);
|
||||
assert!(matches!(
|
||||
working_set.parse_errors.first(),
|
||||
Some(ParseError::UnexpectedRedirection { .. })
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nothing_comparison_neq() {
|
||||
let engine_state = EngineState::new();
|
||||
|
Reference in New Issue
Block a user