diff options
author | Benjamin Peterson <benjamin@python.org> | 2013-05-17 22:35:28 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2013-05-17 22:35:28 (GMT) |
commit | 48953632dfd3e78c4eee8be907a0b7900f46fa8c (patch) | |
tree | 43622878bddb1236d96180862cedeea72eaa6b9b | |
parent | 3e269397e39d2d60a1b74c338a7d321852d71b85 (diff) | |
parent | d2b58a9880d119b20e1fc1c82a3e2e2d9eaa0817 (diff) | |
download | cpython-48953632dfd3e78c4eee8be907a0b7900f46fa8c.zip cpython-48953632dfd3e78c4eee8be907a0b7900f46fa8c.tar.gz cpython-48953632dfd3e78c4eee8be907a0b7900f46fa8c.tar.bz2 |
merge 3.3
-rw-r--r-- | Lib/test/test_unicode.py | 2 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Objects/stringlib/unicode_format.h | 10 |
3 files changed, 13 insertions, 2 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 6a646a0..6680f74 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -943,6 +943,8 @@ class UnicodeTest(string_tests.CommonTest, self.assertEqual("{0:.0s}".format("ABC\u0410\u0411\u0412"), '') + self.assertEqual("{[{}]}".format({"{}": 5}), "5") + def test_format_map(self): self.assertEqual(''.format_map({}), '') self.assertEqual('a'.format_map({}), 'a') @@ -13,6 +13,9 @@ Core and Builtins - Issue #12370: Prevent class bodies from interfering with the __class__ closure. +- Issue #17644: Fix a crash in str.format when curly braces are used in square + brackets. + - Issue #17237: Fix crash in the ASCII decoder on m68k. - Issue #17927: Frame objects kept arguments alive if they had been diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h index 9429169..b01d756 100644 --- a/Objects/stringlib/unicode_format.h +++ b/Objects/stringlib/unicode_format.h @@ -638,7 +638,7 @@ MarkupIterator_next(MarkupIterator *self, SubString *literal, 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 @@ MarkupIterator_next(MarkupIterator *self, SubString *literal, /* 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 '}': |