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/unicodeobject.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/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index d3516fa..58899ad 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -14617,12 +14617,6 @@ unicode_format_arg_format(struct unicode_formatter_t *ctx, if (ctx->fmtcnt == 0) ctx->writer.overallocate = 0; - if (arg->ch == '%') { - if (_PyUnicodeWriter_WriteCharInline(writer, '%') < 0) - return -1; - return 1; - } - v = unicode_format_getnextarg(ctx); if (v == NULL) return -1; @@ -14882,6 +14876,13 @@ unicode_format_arg(struct unicode_formatter_t *ctx) int ret; arg.ch = PyUnicode_READ(ctx->fmtkind, ctx->fmtdata, ctx->fmtpos); + if (arg.ch == '%') { + ctx->fmtpos++; + ctx->fmtcnt--; + if (_PyUnicodeWriter_WriteCharInline(&ctx->writer, '%') < 0) + return -1; + return 0; + } arg.flags = 0; arg.width = -1; arg.prec = -1; @@ -14903,7 +14904,7 @@ unicode_format_arg(struct unicode_formatter_t *ctx) return -1; } - if (ctx->dict && (ctx->argidx < ctx->arglen) && arg.ch != '%') { + if (ctx->dict && (ctx->argidx < ctx->arglen)) { PyErr_SetString(PyExc_TypeError, "not all arguments converted during string formatting"); return -1; |