mirror of
https://github.com/nushell/nushell.git
synced 2024-11-23 00:43:33 +01:00
Improve env shorthand parse (#777)
This commit is contained in:
parent
6514a30b5d
commit
d2d22815fb
@ -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)
|
||||
{
|
||||
|
@ -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/",
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user