diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 057e69c250..f5afdb732d 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -813,14 +813,14 @@ pub fn parse_call( expr: Expr::Call(mut call), span, ty, - custom_completion: None, + custom_completion, } => { call.head = orig_span; Expression { expr: Expr::Call(call), span, ty, - custom_completion: None, + custom_completion, } } x => x, @@ -1869,6 +1869,7 @@ pub fn parse_string( trace!("parsing: string"); let bytes = working_set.get_span_contents(span); + let bytes = trim_quotes(bytes); if let Ok(token) = String::from_utf8(bytes.into()) { @@ -1898,6 +1899,15 @@ pub fn parse_string_strict( trace!("parsing: string, with required delimiters"); let bytes = working_set.get_span_contents(span); + + // Check for unbalanced quotes: + if (bytes.starts_with(b"\"") || (bytes.starts_with(b"$\""))) && !bytes.ends_with(b"\"") { + return (garbage(span), Some(ParseError::Unclosed("\"".into(), span))); + } + if (bytes.starts_with(b"\'") || (bytes.starts_with(b"$\""))) && !bytes.ends_with(b"\'") { + return (garbage(span), Some(ParseError::Unclosed("\'".into(), span))); + } + let (bytes, quoted) = if (bytes.starts_with(b"\"") && bytes.ends_with(b"\"") && bytes.len() > 1) || (bytes.starts_with(b"\'") && bytes.ends_with(b"\'") && bytes.len() > 1) { diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index a714491950..1318e785ec 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -148,3 +148,19 @@ fn alias_with_error_doesnt_panic() -> TestResult { "extra positional", ) } + +#[test] +fn quotes_with_equals() -> TestResult { + run_test( + r#"let query_prefix = "https://api.github.com/search/issues?q=repo:nushell/"; $query_prefix"#, + "https://api.github.com/search/issues?q=repo:nushell/", + ) +} + +#[test] +fn string_interp_with_equals() -> TestResult { + run_test( + r#"let query_prefix = $"https://api.github.com/search/issues?q=repo:nushell/"; $query_prefix"#, + "https://api.github.com/search/issues?q=repo:nushell/", + ) +}