mirror of
https://github.com/python/cpython.git
synced 2026-06-28 11:50:50 +00:00
gh-151238: Check for _get_resized_exprs failure in _PyPegen_{joined,template}_str (#151259)
This commit is contained in:
parent
0066fd73a2
commit
4b44b1e1fd
3 changed files with 19 additions and 0 deletions
|
|
@ -593,6 +593,17 @@ def test_compile_time_concat_errors(self):
|
|||
r"""b'' f''""",
|
||||
])
|
||||
|
||||
def test_concat_decode_failure_does_not_crash(self):
|
||||
script = r'''
|
||||
import builtins
|
||||
builtins.__import__ = builtins # Breaks warning machinery so _get_resized_exprs returns NULL
|
||||
try:
|
||||
compile('"x"f"\]"b""', '<test>', 'exec')
|
||||
except Exception:
|
||||
pass
|
||||
'''
|
||||
assert_python_ok('-c', script)
|
||||
|
||||
def test_literal(self):
|
||||
self.assertEqual(f'', '')
|
||||
self.assertEqual(f'a', 'a')
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Fix a crash when compiling a concatenated f-string or t-string if an error
|
||||
occurs when processing one of it's parts.
|
||||
|
|
@ -1416,6 +1416,9 @@ expr_ty
|
|||
_PyPegen_template_str(Parser *p, Token *a, asdl_expr_seq *raw_expressions, Token *b) {
|
||||
|
||||
asdl_expr_seq *resized_exprs = _get_resized_exprs(p, a, raw_expressions, b, TSTRING);
|
||||
if (resized_exprs == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return _PyAST_TemplateStr(resized_exprs, a->lineno, a->col_offset,
|
||||
b->end_lineno, b->end_col_offset,
|
||||
p->arena);
|
||||
|
|
@ -1425,6 +1428,9 @@ expr_ty
|
|||
_PyPegen_joined_str(Parser *p, Token* a, asdl_expr_seq* raw_expressions, Token*b) {
|
||||
|
||||
asdl_expr_seq *resized_exprs = _get_resized_exprs(p, a, raw_expressions, b, FSTRING);
|
||||
if (resized_exprs == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return _PyAST_JoinedStr(resized_exprs, a->lineno, a->col_offset,
|
||||
b->end_lineno, b->end_col_offset,
|
||||
p->arena);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue