Skip to content

Commit d9f910c

Browse files
Commit
1 parent adb384b commit d9f910c

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

Lib/test/multibytecodec_support.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,11 @@ def test_incrementalencoder_del_segfault(self):
284284

285285
def test_null_terminator(self):
286286
# see gh-101828
287-
if any(enc in self.encoding for enc in ('shift', 'euc_jis')):
288-
text = "バルーンフルーツ"
289-
else:
290-
text = "Spam"
287+
text = "フルーツ"
288+
try:
289+
text.encode(self.encoding)
290+
except UnicodeEncodeError:
291+
text = "Python is cool"
291292
encode_w_null = (text + "\0").encode(self.encoding)
292293
encode_plus_null = text.encode(self.encoding) + "\0".encode(self.encoding)
293294
self.assertTrue(encode_w_null.endswith(b'\x00'))

Modules/cjkcodecs/_codecs_iso2022.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,10 +802,13 @@ jisx0213_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
802802
return coded;
803803

804804
case 2: /* second character of unicode pair */
805-
coded = find_pairencmap((ucs2_t)data[0], (ucs2_t)data[1],
806-
jisx0213_pair_encmap, JISX0213_ENCPAIRS);
807-
if (coded != DBCINV)
808-
return coded;
805+
if (data[1] != 0) { /* Don't consume null char as part of pair */
806+
coded = find_pairencmap((ucs2_t)data[0], (ucs2_t)data[1],
807+
jisx0213_pair_encmap, JISX0213_ENCPAIRS);
808+
if (coded != DBCINV) {
809+
return coded;
810+
}
811+
}
809812
_Py_FALLTHROUGH;
810813

811814
case -1: /* flush unterminated */

0 commit comments

Comments
 (0)