]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
fix format spec recursive expansion (closes #19729)
authorBenjamin Peterson <benjamin@python.org>
Wed, 27 Nov 2013 01:22:36 +0000 (19:22 -0600)
committerBenjamin Peterson <benjamin@python.org>
Wed, 27 Nov 2013 01:22:36 +0000 (19:22 -0600)
Lib/test/test_unicode.py
Misc/NEWS
Objects/stringlib/unicode_format.h

index 9dc3438bea0f1f2c15a17ecd2714d5d920e20a10..502d39368d622517bac227d657c24a899b1dce8d 100644 (file)
@@ -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({}), '')
index 59db14f3e2d2ff0dbcffce9f6a20d9deb5f15c1b..defbf25fa8770880f987b58e66c39d92c354dbf3 100644 (file)
--- 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.
 
index c1c2cf37812a816a1ed9ad18b0b8701c755dfc19..d4719a578bb512653f71512f4b0a420f6e19b691 100644 (file)
@@ -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.