Improve error message when bash-style alias syntax is mistakenly used (#3995)

This commit is contained in:
Tom Panton 2021-09-09 23:44:55 +01:00 committed by GitHub
parent 51c74eebd0
commit 55eafadf02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2025,6 +2025,24 @@ fn parse_alias(call: &LiteCommand, scope: &dyn ParserScope) -> Option<ParseError
{
return None;
}
if call.parts.get(2).map(|part| part.item.as_str()) != Some("=") {
if let Some(equals_span) = [call.parts.get(1), call.parts.get(2)]
.iter()
.flatten()
.filter_map(|part| {
part.find('=')
.map(|offset| Span::for_char(part.span.start() + offset))
})
.next()
{
return Some(ParseError::general_error(
"Invalid alias syntax",
"Expected space on both sides of =".spanned(equals_span),
));
}
}
if call.parts.len() < 4 {
return Some(ParseError::mismatch("alias", call.parts[0].clone()));
}