mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
bpo-29568: Disable any characters between two percents for escaped percent "%%" in the format string for classic string formatting. (GH-513)
This commit is contained in:
parent
c393ee8589
commit
9f8ad3f39e
4 changed files with 57 additions and 58 deletions
|
@ -650,6 +650,12 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
|
|||
#endif
|
||||
|
||||
fmt++;
|
||||
if (*fmt == '%') {
|
||||
*res++ = '%';
|
||||
fmt++;
|
||||
fmtcnt--;
|
||||
continue;
|
||||
}
|
||||
if (*fmt == '(') {
|
||||
const char *keystart;
|
||||
Py_ssize_t keylen;
|
||||
|
@ -794,11 +800,9 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
|
|||
"incomplete format");
|
||||
goto error;
|
||||
}
|
||||
if (c != '%') {
|
||||
v = getnextarg(args, arglen, &argidx);
|
||||
if (v == NULL)
|
||||
goto error;
|
||||
}
|
||||
v = getnextarg(args, arglen, &argidx);
|
||||
if (v == NULL)
|
||||
goto error;
|
||||
|
||||
if (fmtcnt < 0) {
|
||||
/* last writer: disable writer overallocation */
|
||||
|
@ -808,10 +812,6 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
|
|||
sign = 0;
|
||||
fill = ' ';
|
||||
switch (c) {
|
||||
case '%':
|
||||
*res++ = '%';
|
||||
continue;
|
||||
|
||||
case 'r':
|
||||
// %r is only for 2/3 code; 3 only code should use %a
|
||||
case 'a':
|
||||
|
@ -1017,7 +1017,7 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
|
|||
res += (width - len);
|
||||
}
|
||||
|
||||
if (dict && (argidx < arglen) && c != '%') {
|
||||
if (dict && (argidx < arglen)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"not all arguments converted during bytes formatting");
|
||||
Py_XDECREF(temp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue