From 6eb00f6c60e820ea1671926766782e536da0ccca Mon Sep 17 00:00:00 2001 From: Vaishaag Subhagan Date: Mon, 17 Apr 2023 19:51:10 +1000 Subject: [PATCH] Fix strange error on unbalanced curly braces (#8906) # Description Fixes issue https://github.com/nushell/nushell/issues/8400 # User-Facing Changes Before ![image](https://user-images.githubusercontent.com/5063945/232443913-a8fe9f50-2014-4edd-95b0-516058566f64.png) After ![image](https://user-images.githubusercontent.com/5063945/232444266-375d9438-0688-4f49-a884-b8650110f7fe.png) --- crates/nu-parser/src/lex.rs | 2 +- src/tests/test_parser.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/nu-parser/src/lex.rs b/crates/nu-parser/src/lex.rs index a0d7a1af85..40f2baaac4 100644 --- a/crates/nu-parser/src/lex.rs +++ b/crates/nu-parser/src/lex.rs @@ -191,7 +191,7 @@ pub fn lex_item( Some(ParseError::Unbalanced( "{".to_string(), "}".to_string(), - Span::new(span.end, span.end), + Span::new(span.end, span.end + 1), )), ); } diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index 957811cb29..1899efebf5 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -488,6 +488,11 @@ fn unbalanced_delimiter3() -> TestResult { fail_test(r#"{"#, "Unexpected end of code") } +#[test] +fn unbalanced_delimiter4() -> TestResult { + fail_test(r#"}"#, "unbalanced { and }") +} + #[test] fn register_with_string_literal() -> TestResult { fail_test(r#"register 'nu-plugin-math'"#, "File not found")