Improve env shorthand parse (#777)

This commit is contained in:
JT 2022-01-19 09:58:12 -05:00 committed by GitHub
parent 6514a30b5d
commit d2d22815fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -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)
{

View File

@ -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/",
)
}