mirror of
https://github.com/nushell/nushell
synced 2024-12-27 13:33:16 +00:00
Fix parse_string_strict() to detect unbalanced quotes properly (#4928)
This commit is contained in:
parent
ea7c8c237e
commit
90013295aa
1 changed files with 16 additions and 5 deletions
|
@ -2391,17 +2391,28 @@ pub fn parse_string_strict(
|
|||
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 = if bytes.starts_with(b"$") {
|
||||
&bytes[1..]
|
||||
} else {
|
||||
bytes
|
||||
};
|
||||
if bytes.starts_with(b"\"") && (bytes.len() == 1 || !bytes.ends_with(b"\"")) {
|
||||
return (garbage(span), Some(ParseError::Unclosed("\"".into(), span)));
|
||||
}
|
||||
if bytes.starts_with(b"\'") && (bytes.len() == 1 || !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)
|
||||
{
|
||||
(&bytes[1..(bytes.len() - 1)], true)
|
||||
} else if (bytes.starts_with(b"$\"") && bytes.ends_with(b"\"") && bytes.len() > 2)
|
||||
|| (bytes.starts_with(b"$\'") && bytes.ends_with(b"\'") && bytes.len() > 2)
|
||||
{
|
||||
(&bytes[2..(bytes.len() - 1)], true)
|
||||
} else {
|
||||
(bytes, false)
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue