From: Eric Smith Date: Sat, 23 May 2009 14:04:31 +0000 (+0000) Subject: Merged revisions 72848 via svnmerge from X-Git-Tag: v2.6.3rc1~256 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f73758f012268b8c6af6e021fb9f632154144229;p=python Merged revisions 72848 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r72848 | eric.smith | 2009-05-23 09:56:13 -0400 (Sat, 23 May 2009) | 1 line Issue 6089: str.format raises SystemError. ........ --- diff --git a/Lib/test/test_str.py b/Lib/test/test_str.py index 044711cad5..de988a8872 100644 --- a/Lib/test/test_str.py +++ b/Lib/test/test_str.py @@ -351,6 +351,10 @@ class StrTest( self.assertRaises(ValueError, "{:s}".format) self.assertRaises(ValueError, "{}".format) + # issue 6089 + self.assertRaises(ValueError, "{0[0]x}".format, [None]) + self.assertRaises(ValueError, "{0[0](10)}".format, [None]) + # can't have a replacement on the field name portion self.assertRaises(TypeError, '{0[{1}]}'.format, 'abcdefg', 4) diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 968f64b161..96c15f03a3 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1091,6 +1091,10 @@ class UnicodeTest( self.assertRaises(ValueError, u"{:s}".format) self.assertRaises(ValueError, u"{}".format) + # issue 6089 + self.assertRaises(ValueError, u"{0[0]x}".format, [None]) + self.assertRaises(ValueError, u"{0[0](10)}".format, [None]) + # can't have a replacement on the field name portion self.assertRaises(TypeError, u'{0[{1}]}'.format, u'abcdefg', 4) diff --git a/Misc/NEWS b/Misc/NEWS index 61717a05e2..2b1630fd2b 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 2.6.3 Core and Builtins ----------------- +- Issue #6089: str.format can raise SystemError with certain invalid + field specifiers. + - Issue #5994: the marshal module now has docstrings. - Issue #5981: Fix two minor inf/nan issues in float.fromhex: (1) inf diff --git a/Objects/stringlib/string_format.h b/Objects/stringlib/string_format.h index 600e6b04a1..6c531e89c7 100644 --- a/Objects/stringlib/string_format.h +++ b/Objects/stringlib/string_format.h @@ -329,8 +329,9 @@ FieldNameIterator_next(FieldNameIterator *self, int *is_attribute, *name_idx = get_integer(name); break; default: - /* interal error, can't get here */ - assert(0); + /* Invalid character follows ']' */ + PyErr_SetString(PyExc_ValueError, "Only '.' or '[' may " + "follow ']' in format field specifier"); return 0; }