From f59c28c93007d3d7e7340703aa5d2360d285abed Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 9 May 2012 03:24:14 +0200 Subject: [PATCH] unicode_writer_finish() checks string consistency --- Lib/test/test_unicode.py | 4 ++++ Objects/unicodeobject.c | 1 + 2 files changed, 5 insertions(+) diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 8468fbf2c93..2eadd4df074 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1064,6 +1064,10 @@ class UnicodeTest(string_tests.CommonTest, self.assertEqual('%f' % INF, 'inf') self.assertEqual('%F' % INF, 'INF') + # PEP 393 + self.assertEqual('%.1s' % "a\xe9\u20ac", 'a') + self.assertEqual('%.2s' % "a\xe9\u20ac", 'a\xe9') + def test_startswith_endswith_errors(self): for meth in ('foo'.startswith, 'foo'.endswith): with self.assertRaises(TypeError) as cm: diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 0722312373d..2c8378edb05 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -13320,6 +13320,7 @@ unicode_writer_finish(unicode_writer_t *writer) Py_DECREF(writer->buffer); return NULL; } + assert(_PyUnicode_CheckConsistency(writer->buffer, 1)); return writer->buffer; }