[Python-checkins] r72848 - in python/trunk: Lib/test/test_str.py Lib/test/test_unicode.py Objects/stringlib/string_format.h

eric.smith python-checkins at python.org
Sat May 23 15:56:13 CEST 2009


Author: eric.smith
Date: Sat May 23 15:56:13 2009
New Revision: 72848

Log:
Issue 6089: str.format raises SystemError.

Modified:
   python/trunk/Lib/test/test_str.py
   python/trunk/Lib/test/test_unicode.py
   python/trunk/Objects/stringlib/string_format.h

Modified: python/trunk/Lib/test/test_str.py
==============================================================================
--- python/trunk/Lib/test/test_str.py	(original)
+++ python/trunk/Lib/test/test_str.py	Sat May 23 15:56:13 2009
@@ -351,6 +351,10 @@
         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)
 

Modified: python/trunk/Lib/test/test_unicode.py
==============================================================================
--- python/trunk/Lib/test/test_unicode.py	(original)
+++ python/trunk/Lib/test/test_unicode.py	Sat May 23 15:56:13 2009
@@ -1100,6 +1100,10 @@
         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)
 

Modified: python/trunk/Objects/stringlib/string_format.h
==============================================================================
--- python/trunk/Objects/stringlib/string_format.h	(original)
+++ python/trunk/Objects/stringlib/string_format.h	Sat May 23 15:56:13 2009
@@ -375,8 +375,9 @@
         *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;
     }
 


More information about the Python-checkins mailing list