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:
Bahex
2025-07-21 08:14:35 +03:00
committed by GitHub
parent 16167a25ec
commit 30c38b8c49

View File

@ -2003,15 +2003,11 @@ pub fn parse_paren_expr(
let fcp_error_count = working_set.parse_errors.len();
if fcp_error_count > starting_error_count {
let malformed_subexpr = working_set.parse_errors[starting_error_count..]
.iter()
.any(|e| match e {
ParseError::Unclosed(right, _) if right == ")" => true,
ParseError::Unbalanced(left, right, _) if left == "(" && right == ")" => true,
_ => false,
});
.first()
.is_some_and(|e| matches!(e, ParseError::Unclosed(right, _) if right == ")" ));
if malformed_subexpr {
working_set.parse_errors.truncate(starting_error_count);
parse_string(working_set, span)
parse_string_interpolation(working_set, span)
} else {
fcp_expr
}
@ -2250,11 +2246,13 @@ pub fn parse_string_interpolation(working_set: &mut StateWorkingSet, span: Span)
if 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);
output.push(expr);
}
}
}
}
Expression::new(
working_set,