cpython: 3b316ea5aa82 (original) (raw)
Mercurial > cpython
changeset 82058:3b316ea5aa82 3.3
Issue #17137: When an Unicode string is resized, the internal wide character string (wstr) format is now cleared. [#17137]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Thu, 07 Feb 2013 23:12:46 +0100 |
parents | c5fb8bc56def |
children | c10a3ddba483 3942c20bebdb |
files | Lib/test/test_unicode.py Misc/NEWS Objects/unicodeobject.c |
diffstat | 3 files changed, 22 insertions(+), 0 deletions(-)[+] [-] Lib/test/test_unicode.py 15 Misc/NEWS 3 Objects/unicodeobject.c 4 |
line wrap: on
line diff
--- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -2167,6 +2167,21 @@ class UnicodeTest(string_tests.CommonTes self.assertEqual(args[0], text) self.assertEqual(len(args), 1)
- def test_resize(self):
for length in range(1, 100, 7):[](#l1.8)
# generate a fresh string (refcount=1)[](#l1.9)
text = 'a' * length + 'b'[](#l1.10)
# fill wstr internal field[](#l1.12)
abc = text.encode('unicode_internal')[](#l1.13)
self.assertEqual(abc.decode('unicode_internal'), text)[](#l1.14)
# resize text: wstr field must be cleared and then recomputed[](#l1.16)
text += 'c'[](#l1.17)
abcdef = text.encode('unicode_internal')[](#l1.18)
self.assertNotEqual(abc, abcdef)[](#l1.19)
self.assertEqual(abcdef.decode('unicode_internal'), text)[](#l1.20)
+ class StringModuleTest(unittest.TestCase): def test_formatter_parser(self):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 3.3.1? Core and Builtins ----------------- +- Issue #17137: When an Unicode string is resized, the internal wide character
--- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -702,6 +702,10 @@ resize_compact(PyObject *unicode, Py_ssi if (!PyUnicode_IS_ASCII(unicode)) _PyUnicode_WSTR_LENGTH(unicode) = length; }