From 649b3804c18c2ec1b4c5cd4f54c99028cc822350 Mon Sep 17 00:00:00 2001 From: ahkrr <44893716+ahkrr@users.noreply.github.com> Date: Fri, 5 Nov 2021 09:46:46 +0100 Subject: [PATCH] fix: panic! during parsing (#4107) Typing `selector -qa` into nu would cause a `panic!` This was the case because the inner loop incremented the `idx` that was only checked in the outer loop and used it to index into `lite_cmd.parts[idx]` With the fix we now break loop. Co-authored-by: ahkrr --- crates/nu-parser/src/parse.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/nu-parser/src/parse.rs b/crates/nu-parser/src/parse.rs index 287e28f4f7..ac550be5c1 100644 --- a/crates/nu-parser/src/parse.rs +++ b/crates/nu-parser/src/parse.rs @@ -1559,11 +1559,16 @@ fn parse_internal_command( if error.is_none() { error = err; } - } else if error.is_none() { - error = Some(ParseError::argument_error( - lite_cmd.parts[0].clone(), - ArgumentError::MissingValueForName(full_name.to_owned()), - )); + } else { + if error.is_none() { + error = Some(ParseError::argument_error( + lite_cmd.parts[0].clone(), + ArgumentError::MissingValueForName( + full_name.to_owned(), + ), + )); + } + break; } } }