MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_invalid_cb_for_2bytes_seq

Method test_invalid_cb_for_2bytes_seq

Lib/test/test_str.py:2084–2104  ·  view source on GitHub ↗

Test that an 'invalid continuation byte' error is raised when the continuation byte of a 2-bytes sequence is invalid. The start byte is replaced by a single U+FFFD and the second byte is handled separately when errors='replace'. E.g. in the sequence ,

(self)

Source from the content-addressed store, hash-verified

2082 'unexpected end of data')
2083
2084 def test_invalid_cb_for_2bytes_seq(self):
2085 """
2086 Test that an 'invalid continuation byte' error is raised when the
2087 continuation byte of a 2-bytes sequence is invalid. The start byte
2088 is replaced by a single U+FFFD and the second byte is handled
2089 separately when errors='replace'.
2090 E.g. in the sequence <C2 41>, C2 is the start byte of a 2-bytes
2091 sequence, but 41 is not a valid continuation byte because it&#x27;s the
2092 ASCII letter 'A'.
2093 """
2094 FFFD = '\ufffd'
2095 FFFDx2 = FFFD * 2
2096 sequences = [
2097 ('C2 00', FFFD+'\x00'), ('C2 7F', FFFD+'\x7f'),
2098 ('C2 C0', FFFDx2), ('C2 FF', FFFDx2),
2099 ('DF 00', FFFD+'\x00'), ('DF 7F', FFFD+'\x7f'),
2100 ('DF C0', FFFDx2), ('DF FF', FFFDx2),
2101 ]
2102 for seq, res in sequences:
2103 self.assertCorrectUTF8Decoding(bytes.fromhex(seq), res,
2104 'invalid continuation byte')
2105
2106 def test_invalid_cb_for_3bytes_seq(self):
2107 """

Callers

nothing calls this directly

Calls 2

fromhexMethod · 0.45

Tested by

no test coverage detected