diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 30de612f08..c355a5df01 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -1724,6 +1724,16 @@ pub fn parse_brace_expr( // the parse is ambiguous. We'll need to update the parts of the grammar where this is ambiguous // and then revisit the parsing. + if span.end <= (span.start + 1) { + return ( + Expression::garbage(span), + Some(ParseError::Expected( + format!("non-block value: {shape}"), + span, + )), + ); + } + let bytes = working_set.get_span_contents(Span::new(span.start + 1, span.end - 1)); let (tokens, _) = lex(bytes, span.start + 1, &[b'\r', b'\n', b'\t'], &[b':'], true); diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index 0cc2f9a71c..9c754ca470 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -482,3 +482,8 @@ fn unbalanced_delimiter() -> TestResult { fn unbalanced_delimiter2() -> TestResult { fail_test(r#"{}#.}"#, "unbalanced { and }") } + +#[test] +fn unbalanced_delimiter3() -> TestResult { + fail_test(r#"{"#, "Unexpected end of code") +}