From: Eric Smith Date: Sat, 23 May 2009 13:56:13 +0000 (+0000) Subject: Issue 6089: str.format raises SystemError. X-Git-Tag: v2.7a1~1123 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b94b192ff38f37b99f04605fd6515d7fb97ffea;p=python Issue 6089: str.format raises SystemError. --- diff --git a/Lib/test/test_str.py b/Lib/test/test_str.py index 51d2680adc..5341af218d 100644 --- a/Lib/test/test_str.py +++ b/Lib/test/test_str.py @@ -351,6 +351,10 @@ class StrTest( self.assertRaises(IndexError, "{:s}".format) self.assertRaises(IndexError, "{}".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 83bc5846af..99155ec8df 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1100,6 +1100,10 @@ class UnicodeTest( self.assertRaises(IndexError, u"{:s}".format) self.assertRaises(IndexError, 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/Objects/stringlib/string_format.h b/Objects/stringlib/string_format.h index ce7c90967b..ee6533e44b 100644 --- a/Objects/stringlib/string_format.h +++ b/Objects/stringlib/string_format.h @@ -375,8 +375,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; }