mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
gh-105194: Fix format specifier escaped characters in f-strings (#105231)
This commit is contained in:
parent
4bfa01b9d9
commit
41de54378d
6 changed files with 34 additions and 2 deletions
|
@ -1350,6 +1350,25 @@ _PyPegen_joined_str(Parser *p, Token* a, asdl_expr_seq* raw_expressions, Token*b
|
|||
p->arena);
|
||||
}
|
||||
|
||||
expr_ty _PyPegen_decoded_constant_from_token(Parser* p, Token* tok) {
|
||||
Py_ssize_t bsize;
|
||||
char* bstr;
|
||||
if (PyBytes_AsStringAndSize(tok->bytes, &bstr, &bsize) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
PyObject* str = _PyPegen_decode_string(p, 0, bstr, bsize, tok);
|
||||
if (str == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (_PyArena_AddPyObject(p->arena, str) < 0) {
|
||||
Py_DECREF(str);
|
||||
return NULL;
|
||||
}
|
||||
return _PyAST_Constant(str, NULL, tok->lineno, tok->col_offset,
|
||||
tok->end_lineno, tok->end_col_offset,
|
||||
p->arena);
|
||||
}
|
||||
|
||||
expr_ty _PyPegen_constant_from_token(Parser* p, Token* tok) {
|
||||
char* bstr = PyBytes_AsString(tok->bytes);
|
||||
if (bstr == NULL) {
|
||||
|
|
2
Parser/parser.c
generated
2
Parser/parser.c
generated
|
@ -16323,7 +16323,7 @@ fstring_format_spec_rule(Parser *p)
|
|||
)
|
||||
{
|
||||
D(fprintf(stderr, "%*c+ fstring_format_spec[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "FSTRING_MIDDLE"));
|
||||
_res = _PyPegen_constant_from_token ( p , t );
|
||||
_res = _PyPegen_decoded_constant_from_token ( p , t );
|
||||
if (_res == NULL && PyErr_Occurred()) {
|
||||
p->error_indicator = 1;
|
||||
p->level--;
|
||||
|
|
|
@ -328,6 +328,7 @@ expr_ty _PyPegen_collect_call_seqs(Parser *, asdl_expr_seq *, asdl_seq *,
|
|||
int lineno, int col_offset, int end_lineno,
|
||||
int end_col_offset, PyArena *arena);
|
||||
expr_ty _PyPegen_constant_from_token(Parser* p, Token* tok);
|
||||
expr_ty _PyPegen_decoded_constant_from_token(Parser* p, Token* tok);
|
||||
expr_ty _PyPegen_constant_from_string(Parser* p, Token* tok);
|
||||
expr_ty _PyPegen_concatenate_strings(Parser *p, asdl_expr_seq *, int, int, int, int, PyArena *);
|
||||
expr_ty _PyPegen_FetchRawForm(Parser *p, int, int, int, int);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue