mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Closes #23247: Fix a crash in the StreamWriter.reset() of CJK codecs
This commit is contained in:
parent
b37f43f94b
commit
579db160b3
3 changed files with 12 additions and 0 deletions
|
@ -270,6 +270,13 @@ class TestBase:
|
||||||
|
|
||||||
self.assertEqual(ostream.getvalue(), self.tstring[0])
|
self.assertEqual(ostream.getvalue(), self.tstring[0])
|
||||||
|
|
||||||
|
def test_streamwriter_reset_no_pending(self):
|
||||||
|
# Issue #23247: Calling reset() on a fresh StreamWriter instance
|
||||||
|
# (without pending data) must not crash
|
||||||
|
stream = BytesIO()
|
||||||
|
writer = self.writer(stream)
|
||||||
|
writer.reset()
|
||||||
|
|
||||||
|
|
||||||
class TestBase_Mapping(unittest.TestCase):
|
class TestBase_Mapping(unittest.TestCase):
|
||||||
pass_enctest = []
|
pass_enctest = []
|
||||||
|
|
|
@ -66,6 +66,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #23247: Fix a crash in the StreamWriter.reset() of CJK codecs.
|
||||||
|
|
||||||
- Issue #18622: unittest.mock.mock_open().reset_mock would recurse infinitely.
|
- Issue #18622: unittest.mock.mock_open().reset_mock would recurse infinitely.
|
||||||
Patch from Nicola Palumbo and Laurent De Buyst.
|
Patch from Nicola Palumbo and Laurent De Buyst.
|
||||||
|
|
||||||
|
|
|
@ -1629,6 +1629,9 @@ mbstreamwriter_reset(MultibyteStreamWriterObject *self)
|
||||||
{
|
{
|
||||||
PyObject *pwrt;
|
PyObject *pwrt;
|
||||||
|
|
||||||
|
if (!self->pending)
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
|
||||||
pwrt = multibytecodec_encode(self->codec, &self->state,
|
pwrt = multibytecodec_encode(self->codec, &self->state,
|
||||||
self->pending, NULL, self->errors,
|
self->pending, NULL, self->errors,
|
||||||
MBENC_FLUSH | MBENC_RESET);
|
MBENC_FLUSH | MBENC_RESET);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue