mirror of
https://github.com/nushell/nushell
synced 2025-01-14 06:04:09 +00:00
Improve env shorthand parse (#777)
This commit is contained in:
parent
6514a30b5d
commit
d2d22815fb
2 changed files with 28 additions and 2 deletions
|
@ -813,14 +813,14 @@ pub fn parse_call(
|
||||||
expr: Expr::Call(mut call),
|
expr: Expr::Call(mut call),
|
||||||
span,
|
span,
|
||||||
ty,
|
ty,
|
||||||
custom_completion: None,
|
custom_completion,
|
||||||
} => {
|
} => {
|
||||||
call.head = orig_span;
|
call.head = orig_span;
|
||||||
Expression {
|
Expression {
|
||||||
expr: Expr::Call(call),
|
expr: Expr::Call(call),
|
||||||
span,
|
span,
|
||||||
ty,
|
ty,
|
||||||
custom_completion: None,
|
custom_completion,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x => x,
|
x => x,
|
||||||
|
@ -1869,6 +1869,7 @@ pub fn parse_string(
|
||||||
trace!("parsing: string");
|
trace!("parsing: string");
|
||||||
|
|
||||||
let bytes = working_set.get_span_contents(span);
|
let bytes = working_set.get_span_contents(span);
|
||||||
|
|
||||||
let bytes = trim_quotes(bytes);
|
let bytes = trim_quotes(bytes);
|
||||||
|
|
||||||
if let Ok(token) = String::from_utf8(bytes.into()) {
|
if let Ok(token) = String::from_utf8(bytes.into()) {
|
||||||
|
@ -1898,6 +1899,15 @@ pub fn parse_string_strict(
|
||||||
trace!("parsing: string, with required delimiters");
|
trace!("parsing: string, with required delimiters");
|
||||||
|
|
||||||
let bytes = working_set.get_span_contents(span);
|
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)
|
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)
|
|| (bytes.starts_with(b"\'") && bytes.ends_with(b"\'") && bytes.len() > 1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -148,3 +148,19 @@ fn alias_with_error_doesnt_panic() -> TestResult {
|
||||||
"extra positional",
|
"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 a new issue