mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 20:27:44 +02:00
fix(parser): repeated (
/ parenthesis / opened sub-expressions causes memory leak (#16204)
- fixes #16186 # Description Don't attempt further parsing when there is no complete sub-expression. --------- Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
This commit is contained in:
@ -2003,15 +2003,11 @@ pub fn parse_paren_expr(
|
|||||||
let fcp_error_count = working_set.parse_errors.len();
|
let fcp_error_count = working_set.parse_errors.len();
|
||||||
if fcp_error_count > starting_error_count {
|
if fcp_error_count > starting_error_count {
|
||||||
let malformed_subexpr = working_set.parse_errors[starting_error_count..]
|
let malformed_subexpr = working_set.parse_errors[starting_error_count..]
|
||||||
.iter()
|
.first()
|
||||||
.any(|e| match e {
|
.is_some_and(|e| matches!(e, ParseError::Unclosed(right, _) if right == ")" ));
|
||||||
ParseError::Unclosed(right, _) if right == ")" => true,
|
|
||||||
ParseError::Unbalanced(left, right, _) if left == "(" && right == ")" => true,
|
|
||||||
_ => false,
|
|
||||||
});
|
|
||||||
if malformed_subexpr {
|
if malformed_subexpr {
|
||||||
working_set.parse_errors.truncate(starting_error_count);
|
working_set.parse_errors.truncate(starting_error_count);
|
||||||
parse_string(working_set, span)
|
parse_string_interpolation(working_set, span)
|
||||||
} else {
|
} else {
|
||||||
fcp_expr
|
fcp_expr
|
||||||
}
|
}
|
||||||
@ -2250,11 +2246,13 @@ pub fn parse_string_interpolation(working_set: &mut StateWorkingSet, span: Span)
|
|||||||
if token_start < end {
|
if token_start < end {
|
||||||
let span = Span::new(token_start, end);
|
let span = Span::new(token_start, end);
|
||||||
|
|
||||||
|
if delimiter_stack.is_empty() {
|
||||||
let expr = parse_full_cell_path(working_set, None, span);
|
let expr = parse_full_cell_path(working_set, None, span);
|
||||||
output.push(expr);
|
output.push(expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Expression::new(
|
Expression::new(
|
||||||
working_set,
|
working_set,
|
||||||
|
Reference in New Issue
Block a user