diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-08 03:51:19 (GMT) |
---|---|---|
committer | Xiang Zhang <angwerzx@126.com> | 2017-03-08 03:51:19 (GMT) |
commit | 9f8ad3f39e0a92ed37d012b9dd237399524f0d51 (patch) | |
tree | 1c68aab772250ca4867e95b3f6d6f802a5b3f2bc /Objects/bytesobject.c | |
parent | c393ee858932f79bd6dabf31550f9a53ea90bc68 (diff) | |
download | cpython-9f8ad3f39e0a92ed37d012b9dd237399524f0d51.zip cpython-9f8ad3f39e0a92ed37d012b9dd237399524f0d51.tar.gz cpython-9f8ad3f39e0a92ed37d012b9dd237399524f0d51.tar.bz2 |
bpo-29568: Disable any characters between two percents for escaped percent "%%" in the format string for classic string formatting. (GH-513)
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r-- | Objects/bytesobject.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index f0ddb95..3b15247 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -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); |