From eb12fffbc6f86d8085629d1d565d56add3464ed0 Mon Sep 17 00:00:00 2001 From: pwygab <88221256+merelymyself@users.noreply.github.com> Date: Mon, 30 May 2022 04:16:41 +0800 Subject: [PATCH] prevent panic with `let` alone in pipeline (#5676) * prevent panic with `let` alone in pipeline * Update parser.rs --- crates/nu-parser/src/parser.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 5ecef6cca2..d3506dc722 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -4372,9 +4372,16 @@ pub fn parse_expression( ) .0, Some(ParseError::LetInPipeline( - String::from_utf8_lossy(working_set.get_span_contents(spans[spans.len() - 1])) - .to_string(), - String::from_utf8_lossy(working_set.get_span_contents(spans[1])).to_string(), + String::from_utf8_lossy(match spans.len() { + 1 | 2 | 3 => b"value", + _ => working_set.get_span_contents(spans[3]), + }) + .to_string(), + String::from_utf8_lossy(match spans.len() { + 1 => b"variable", + _ => working_set.get_span_contents(spans[1]), + }) + .to_string(), spans[0], )), ),