diff -r 60b18d7fbe24 Objects/stringlib/unicode_format.h --- a/Objects/stringlib/unicode_format.h Sat Apr 06 16:48:55 2013 +0200 +++ b/Objects/stringlib/unicode_format.h Sat Apr 06 13:11:15 2013 -0400 @@ -633,17 +633,17 @@ MarkupIterator_init(MarkupIterator *self /* returns 0 on error, 1 on non-error termination, and 2 if it got a string (or something to be expanded) */ static int MarkupIterator_next(MarkupIterator *self, SubString *literal, int *field_present, SubString *field_name, 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; Py_ssize_t len; int markup_follows = 0; /* initialize all of the output variables */ SubString_init(literal, NULL, 0, 0); @@ -718,22 +718,28 @@ MarkupIterator_next(MarkupIterator *self format_specs cannot have braces in them. */ *field_present = 1; count = 1; start = self->str.start; /* 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 '}': count--; if (count <= 0) { /* we're done. parse and get out */ SubString s;