mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #5640: Fix Shift-JIS incremental encoder for error handlers different
than strict
This commit is contained in:
parent
fa0fdb89e9
commit
d6703b5e38
3 changed files with 8 additions and 1 deletions
|
@ -107,6 +107,10 @@ class Test_IncrementalEncoder(unittest.TestCase):
|
||||||
self.assertRaises(UnicodeEncodeError, encoder.encode, u'\u0123')
|
self.assertRaises(UnicodeEncodeError, encoder.encode, u'\u0123')
|
||||||
self.assertEqual(encoder.encode(u'', True), '\xa9\xdc')
|
self.assertEqual(encoder.encode(u'', True), '\xa9\xdc')
|
||||||
|
|
||||||
|
def test_issue5640(self):
|
||||||
|
encoder = codecs.getincrementalencoder('shift-jis')('backslashreplace')
|
||||||
|
self.assertEqual(encoder.encode(u'\xff'), b'\\xff')
|
||||||
|
self.assertEqual(encoder.encode(u'\n'), b'\n')
|
||||||
|
|
||||||
class Test_IncrementalDecoder(unittest.TestCase):
|
class Test_IncrementalDecoder(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,9 @@ C-API
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #5640: Fix Shift-JIS incremental encoder for error handlers different
|
||||||
|
than strict
|
||||||
|
|
||||||
- Issue #8782: Add a trailing newline in linecache.updatecache to the last line
|
- Issue #8782: Add a trailing newline in linecache.updatecache to the last line
|
||||||
of files without one.
|
of files without one.
|
||||||
|
|
||||||
|
|
|
@ -498,7 +498,6 @@ multibytecodec_encode(MultibyteCodec *codec,
|
||||||
outleft = (Py_ssize_t)(buf.outbuf_end - buf.outbuf);
|
outleft = (Py_ssize_t)(buf.outbuf_end - buf.outbuf);
|
||||||
r = codec->encode(state, codec->config, &buf.inbuf, inleft,
|
r = codec->encode(state, codec->config, &buf.inbuf, inleft,
|
||||||
&buf.outbuf, outleft, flags);
|
&buf.outbuf, outleft, flags);
|
||||||
*data = buf.inbuf;
|
|
||||||
if ((r == 0) || (r == MBERR_TOOFEW && !(flags & MBENC_FLUSH)))
|
if ((r == 0) || (r == MBERR_TOOFEW && !(flags & MBENC_FLUSH)))
|
||||||
break;
|
break;
|
||||||
else if (multibytecodec_encerror(codec, state, &buf, errors,r))
|
else if (multibytecodec_encerror(codec, state, &buf, errors,r))
|
||||||
|
@ -528,6 +527,7 @@ multibytecodec_encode(MultibyteCodec *codec,
|
||||||
if (_PyString_Resize(&buf.outobj, finalsize) == -1)
|
if (_PyString_Resize(&buf.outobj, finalsize) == -1)
|
||||||
goto errorexit;
|
goto errorexit;
|
||||||
|
|
||||||
|
*data = buf.inbuf;
|
||||||
Py_XDECREF(buf.excobj);
|
Py_XDECREF(buf.excobj);
|
||||||
return buf.outobj;
|
return buf.outobj;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue