File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -2303,6 +2303,23 @@ def test_resize(self):
2303
2303
self .assertNotEqual (abc , abcdef )
2304
2304
self .assertEqual (abcdef .decode ('unicode_internal' ), text )
2305
2305
2306
+ @support .cpython_only
2307
+ def test_pep393_utf8_caching_bug (self ):
2308
+ # Issue #25709: Problem with string concatenation and utf-8 cache
2309
+ from _testcapi import getargs_s_hash
2310
+ for k in 0x24 , 0xa4 , 0x20ac , 0x1f40d :
2311
+ s = ''
2312
+ for i in range (5 ):
2313
+ # Due to CPython specific optimization the 's' string can be
2314
+ # resized in-place.
2315
+ s += chr (k )
2316
+ # Parsing with the "s#" format code calls indirectly
2317
+ # PyUnicode_AsUTF8AndSize() which creates the UTF-8
2318
+ # encoded string cached in the Unicode object.
2319
+ self .assertEqual (getargs_s_hash (s ), chr (k ).encode () * (i + 1 ))
2320
+ # Check that the second call returns the same result
2321
+ self .assertEqual (getargs_s_hash (s ), chr (k ).encode () * (i + 1 ))
2322
+
2306
2323
2307
2324
class StringModuleTest (unittest .TestCase ):
2308
2325
def test_formatter_parser (self ):
Original file line number Diff line number Diff line change @@ -10,8 +10,13 @@ What's New in Python 3.3.7?
10
10
Core and Builtins
11
11
-----------------
12
12
13
+ - Issue #25709: Fixed problem with in-place string concatenation and utf-8 cache.
14
+
13
15
- Issue #24407: Fix crash when dict is mutated while being updated.
14
16
17
+ - Issue #24097: Fixed crash in object.__reduce__() if slot name is freed inside
18
+ __getattr__.
19
+
15
20
- Issue #24096: Make warnings.warn_explicit more robust against mutation of the
16
21
warnings.filters list.
17
22
Original file line number Diff line number Diff line change @@ -679,6 +679,11 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
679
679
}
680
680
new_size = (struct_size + (length + 1 ) * char_size );
681
681
682
+ if (_PyUnicode_HAS_UTF8_MEMORY (unicode )) {
683
+ PyObject_DEL (_PyUnicode_UTF8 (unicode ));
684
+ _PyUnicode_UTF8 (unicode ) = NULL ;
685
+ _PyUnicode_UTF8_LENGTH (unicode ) = 0 ;
686
+ }
682
687
_Py_DEC_REFTOTAL ;
683
688
_Py_ForgetReference (unicode );
684
689
You can’t perform that action at this time.
0 commit comments