Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Commit
  • Loading branch information
StanFromIreland committed Oct 7, 2025
commit d9f910caaa6765383b3031f298a64406f49f9e5e
9 changes: 5 additions & 4 deletions Lib/test/multibytecodec_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,11 @@ def test_incrementalencoder_del_segfault(self):

def test_null_terminator(self):
# see gh-101828
if any(enc in self.encoding for enc in ('shift', 'euc_jis')):
text = "バルーンフルーツ"
else:
text = "Spam"
text = "フルーツ"
try:
text.encode(self.encoding)
except UnicodeEncodeError:
text = "Python is cool"
encode_w_null = (text + "\0").encode(self.encoding)
encode_plus_null = text.encode(self.encoding) + "\0".encode(self.encoding)
self.assertTrue(encode_w_null.endswith(b'\x00'))
Expand Down
11 changes: 7 additions & 4 deletions Modules/cjkcodecs/_codecs_iso2022.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,13 @@ jisx0213_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
return coded;

case 2: /* second character of unicode pair */
coded = find_pairencmap((ucs2_t)data[0], (ucs2_t)data[1],
jisx0213_pair_encmap, JISX0213_ENCPAIRS);
if (coded != DBCINV)
return coded;
if (data[1] != 0) { /* Don't consume null char as part of pair */
coded = find_pairencmap((ucs2_t)data[0], (ucs2_t)data[1],
jisx0213_pair_encmap, JISX0213_ENCPAIRS);
if (coded != DBCINV) {
return coded;
}
}
_Py_FALLTHROUGH;

case -1: /* flush unterminated */
Expand Down
Loading