diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-21 22:50:28 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-21 22:50:28 (GMT) |
commit | d6703b5e38baac6b85c1c2cf9311e11e4916984b (patch) | |
tree | 5cb3fb2d2ae8fe340ed8a89b9b1fc3896b7bcb50 | |
parent | fa0fdb89e98fbbec7da9891dde2647fb951888c8 (diff) | |
download | cpython-d6703b5e38baac6b85c1c2cf9311e11e4916984b.zip cpython-d6703b5e38baac6b85c1c2cf9311e11e4916984b.tar.gz cpython-d6703b5e38baac6b85c1c2cf9311e11e4916984b.tar.bz2 |
Issue #5640: Fix Shift-JIS incremental encoder for error handlers different
than strict
-rw-r--r-- | Lib/test/test_multibytecodec.py | 4 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Modules/cjkcodecs/multibytecodec.c | 2 |
3 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py index 517a682..95ca0ab 100644 --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -107,6 +107,10 @@ class Test_IncrementalEncoder(unittest.TestCase): self.assertRaises(UnicodeEncodeError, encoder.encode, u'\u0123') 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): @@ -29,6 +29,9 @@ C-API 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 of files without one. diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c index 56251f3..1f31595 100644 --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -498,7 +498,6 @@ multibytecodec_encode(MultibyteCodec *codec, outleft = (Py_ssize_t)(buf.outbuf_end - buf.outbuf); r = codec->encode(state, codec->config, &buf.inbuf, inleft, &buf.outbuf, outleft, flags); - *data = buf.inbuf; if ((r == 0) || (r == MBERR_TOOFEW && !(flags & MBENC_FLUSH))) break; else if (multibytecodec_encerror(codec, state, &buf, errors,r)) @@ -528,6 +527,7 @@ multibytecodec_encode(MultibyteCodec *codec, if (_PyString_Resize(&buf.outobj, finalsize) == -1) goto errorexit; + *data = buf.inbuf; Py_XDECREF(buf.excobj); return buf.outobj; |