diff Objects/stringlib/unicode_format.h @ 83817:6786e681ed58 3.3

only recursively expand in the format spec (closes #17644)
author Benjamin Peterson <benjamin@python.org>
date Fri, 17 May 2013 17:34:30 -0500
parents 629af342b189
children bab7dc2ffc16 9f6684820b5f
line wrap: on
line diff
--- a/Objects/stringlib/unicode_format.h	Fri May 17 03:01:13 2013 -0700
+++ b/Objects/stringlib/unicode_format.h	Fri May 17 17:34:30 2013 -0500
@@ -638,7 +638,7 @@
                     SubString *format_spec, Py_UCS4 *conversion,
                     int *format_spec_needs_expanding)
 {
-    int at_end;
+    int at_end, hit_format_spec;
     Py_UCS4 c = 0;
     Py_ssize_t start;
     int count;
@@ -723,12 +723,18 @@
 
     /* we know we can't have a zero length string, so don't worry
        about that case */
+    hit_format_spec = 0;
     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;
+            break;
         case '{':
             /* the format spec needs to be recursively expanded.
                this is an optimization, and not strictly needed */
-            *format_spec_needs_expanding = 1;
+            if (hit_format_spec)
+                *format_spec_needs_expanding = 1;
             count++;
             break;
         case '}':