diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index daf00cc36e..cf6e5060c4 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -3127,6 +3127,17 @@ fn parse_list_shape( // overflows with spans let end = if bytes.ends_with(b">") { span.end - 1 + // extra characters after the > + } else if bytes.contains(&b'>') { + let angle_start = bytes.split(|it| it == &b'>').collect::>()[0].len() + 1; + let span = Span::new(span.start + angle_start, span.end); + + let err = ParseError::LabeledError( + "Extra characters in the parameter name".into(), + "extra characters".into(), + span, + ); + return (SyntaxShape::Any, Some(err)); } else { let err = ParseError::Unclosed(">".into(), span); return (SyntaxShape::List(Box::new(SyntaxShape::Any)), Some(err)); diff --git a/src/tests/test_signatures.rs b/src/tests/test_signatures.rs index dd06f40d63..571d140863 100644 --- a/src/tests/test_signatures.rs +++ b/src/tests/test_signatures.rs @@ -125,3 +125,10 @@ fn list_annotations_with_default_val_2() -> TestResult { let expected = "Default value wrong type"; fail_test(input, expected) } + +#[test] +fn list_annotations_with_extra_characters() -> TestResult { + let input = "def run [list: listextra] {$list | length}; run [1 2 3]"; + let expected = "Extra characters in the parameter name"; + fail_test(input, expected) +}