Bug description:
Encoding non-ASCII text to ISO-2022-CN-EXT returns b'' with no error. The ASCII part is
lost with it, and the codec reports the whole input as consumed:
>>> 'ABC中DEF'.encode('iso-2022-cn-ext')
b''
>>> codecs.iconv_encode('ISO-2022-CN-EXT', '中') # (output, consumed)
(b'', 1)
>>> codecs.iconv_encode('ISO-2022-CN', '中') # without EXT
(b'\x1b$)A\x0eVP\x0f', 1)
No error handler changes it: strict, replace, ignore and xmlcharrefreplace all give
b''. Only strings stored as 2-byte characters are affected; a pure-ASCII string encodes
normally, and an unencodable character in a 1-byte or 4-byte string raises
UnicodeEncodeError as expected.
This is not an iconv limitation. iconv -f UCS-2LE -t ISO-2022-CN-EXT, which is the
conversion the codec asks for on a 2-byte string, produces the expected
\x1b$)A\x0eVP\x0f.
The iconv codecs are new in 3.16 (gh-152997), so no released version is affected.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Bug description:
Encoding non-ASCII text to ISO-2022-CN-EXT returns
b''with no error. The ASCII part islost with it, and the codec reports the whole input as consumed:
No error handler changes it:
strict,replace,ignoreandxmlcharrefreplaceall giveb''. Only strings stored as 2-byte characters are affected; a pure-ASCII string encodesnormally, and an unencodable character in a 1-byte or 4-byte string raises
UnicodeEncodeErroras expected.This is not an iconv limitation.
iconv -f UCS-2LE -t ISO-2022-CN-EXT, which is theconversion the codec asks for on a 2-byte string, produces the expected
\x1b$)A\x0eVP\x0f.The iconv codecs are new in 3.16 (gh-152997), so no released version is affected.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs