From f016a5cb728966a61b595badb86f1028af37ba89 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Fri, 7 Jan 2022 08:06:54 +1100 Subject: [PATCH] Fix short flags with extra (#696) --- crates/nu-parser/src/parser.rs | 38 +++++++++++++--------------------- src/tests/test_parser.rs | 5 +++++ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index b267ae6d31..35c39647b9 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -2350,31 +2350,21 @@ pub fn parse_signature_helper( error = error.or_else(|| { Some(ParseError::Expected("short flag".into(), span)) }); - - args.push(Arg::Flag(Flag { - arg: None, - desc: String::new(), - long: String::new(), - short: None, - required: false, - var_id: None, - })); - } else { - let mut encoded_var_name = vec![0u8; 4]; - let len = chars[0].encode_utf8(&mut encoded_var_name).len(); - let variable_name = encoded_var_name[0..len].to_vec(); - let var_id = - working_set.add_variable(variable_name, Type::Unknown); - - args.push(Arg::Flag(Flag { - arg: None, - desc: String::new(), - long: String::new(), - short: Some(chars[0]), - required: false, - var_id: Some(var_id), - })); } + + let mut encoded_var_name = vec![0u8; 4]; + let len = chars[0].encode_utf8(&mut encoded_var_name).len(); + let variable_name = encoded_var_name[0..len].to_vec(); + let var_id = working_set.add_variable(variable_name, Type::Unknown); + + args.push(Arg::Flag(Flag { + arg: None, + desc: String::new(), + long: String::new(), + short: Some(chars[0]), + required: false, + var_id: Some(var_id), + })); } else if contents.starts_with(b"(-") { let short_flag = &contents[2..]; diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index 53324d9c86..ac27807666 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -134,3 +134,8 @@ fn multiline_pipe_in_block() -> TestResult { "5", ) } + +#[test] +fn bad_short_flag() -> TestResult { + fail_test(r#"def foo3 [-l?:int] { $l }"#, "short flag") +}