From: Benjamin Peterson Date: Wed, 27 Nov 2013 01:22:36 +0000 (-0600) Subject: fix format spec recursive expansion (closes #19729) X-Git-Tag: v3.4.0b2~459^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0ee22bf7743dc9a6d593c432f787d7bfe70be199;p=thirdparty%2FPython%2Fcpython.git fix format spec recursive expansion (closes #19729) --- diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 9dc3438bea0f..502d39368d62 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -955,6 +955,7 @@ class UnicodeTest(string_tests.CommonTest, '') self.assertEqual("{[{}]}".format({"{}": 5}), "5") + self.assertEqual("0x{:0{:d}X}".format(0x0,16), "0x0000000000000000") def test_format_map(self): self.assertEqual(''.format_map({}), '') diff --git a/Misc/NEWS b/Misc/NEWS index 59db14f3e2d2..defbf25fa877 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ What's New in Python 3.3.4 release candidate 1? Core and Builtins ----------------- +- Issue #19729: In str.format(), fix recursive expansion in format spec. + - Issue #19638: Fix possible crash / undefined behaviour from huge (more than 2 billion characters) input strings in _Py_dg_strtod. diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h index c1c2cf37812a..d4719a578bb5 100644 --- a/Objects/stringlib/unicode_format.h +++ b/Objects/stringlib/unicode_format.h @@ -727,8 +727,10 @@ MarkupIterator_next(MarkupIterator *self, SubString *literal, while (self->str.start < self->str.end) { switch (c = PyUnicode_READ_CHAR(self->str.str, self->str.start++)) { case ':': - hit_format_spec = 1; - count = 1; + if (!hit_format_spec) { + count = 1; + hit_format_spec = 1; + } break; case '{': /* the format spec needs to be recursively expanded.