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

Method test_invalid_cb_for_4bytes_seq

Lib/test/test_str.py:2164–2241  ·  view source on GitHub ↗

Test that an 'invalid continuation byte' error is raised when the continuation byte(s) of a 4-bytes sequence are invalid. When errors='replace',the start byte and all the following valid continuation bytes are replaced with a single U+FFFD, and all the bytes

(self)

Source from the content-addressed store, hash-verified

2162 'invalid continuation byte')
2163
2164 def test_invalid_cb_for_4bytes_seq(self):
2165 """
2166 Test that an 'invalid continuation byte' error is raised when the
2167 continuation byte(s) of a 4-bytes sequence are invalid. When
2168 errors='replace',the start byte and all the following valid
2169 continuation bytes are replaced with a single U+FFFD, and all the bytes
2170 starting from the first invalid continuation bytes (included) are
2171 handled separately.
2172 E.g. in the sequence <E1 80 41>, E1 is the start byte of a 3-bytes
2173 sequence, 80 is a valid continuation byte, but 41 is not a valid cb
2174 because it's the ASCII letter 'A&#x27;.
2175 Note: when the start byte is E0 or ED, the valid ranges for the first
2176 continuation byte are limited to A0..BF and 80..9F respectively.
2177 However, when the start byte is ED, Python 2 considers all the bytes
2178 in range 80..BF valid. This is fixed in Python 3.
2179 """
2180 FFFD = '\ufffd'
2181 FFFDx2 = FFFD * 2
2182 sequences = [
2183 ('F0 00', FFFD+'\x00'), ('F0 7F', FFFD+'\x7f'), ('F0 80', FFFDx2),
2184 ('F0 8F', FFFDx2), ('F0 C0', FFFDx2), ('F0 FF', FFFDx2),
2185 ('F0 90 00', FFFD+'\x00'), ('F0 90 7F', FFFD+'\x7f'),
2186 ('F0 90 C0', FFFDx2), ('F0 90 FF', FFFDx2),
2187 ('F0 BF 00', FFFD+'\x00'), ('F0 BF 7F', FFFD+'\x7f'),
2188 ('F0 BF C0', FFFDx2), ('F0 BF FF', FFFDx2),
2189 ('F0 90 80 00', FFFD+'\x00'), ('F0 90 80 7F', FFFD+'\x7f'),
2190 ('F0 90 80 C0', FFFDx2), ('F0 90 80 FF', FFFDx2),
2191 ('F0 90 BF 00', FFFD+'\x00'), ('F0 90 BF 7F', FFFD+'\x7f'),
2192 ('F0 90 BF C0', FFFDx2), ('F0 90 BF FF', FFFDx2),
2193 ('F0 BF 80 00', FFFD+'\x00'), ('F0 BF 80 7F', FFFD+'\x7f'),
2194 ('F0 BF 80 C0', FFFDx2), ('F0 BF 80 FF', FFFDx2),
2195 ('F0 BF BF 00', FFFD+'\x00'), ('F0 BF BF 7F', FFFD+'\x7f'),
2196 ('F0 BF BF C0', FFFDx2), ('F0 BF BF FF', FFFDx2),
2197 ('F1 00', FFFD+'\x00'), ('F1 7F', FFFD+'\x7f'), ('F1 C0', FFFDx2),
2198 ('F1 FF', FFFDx2), ('F1 80 00', FFFD+'\x00'),
2199 ('F1 80 7F', FFFD+'\x7f'), ('F1 80 C0', FFFDx2),
2200 ('F1 80 FF', FFFDx2), ('F1 BF 00', FFFD+'\x00'),
2201 ('F1 BF 7F', FFFD+'\x7f'), ('F1 BF C0', FFFDx2),
2202 ('F1 BF FF', FFFDx2), ('F1 80 80 00', FFFD+'\x00'),
2203 ('F1 80 80 7F', FFFD+'\x7f'), ('F1 80 80 C0', FFFDx2),
2204 ('F1 80 80 FF', FFFDx2), ('F1 80 BF 00', FFFD+'\x00'),
2205 ('F1 80 BF 7F', FFFD+'\x7f'), ('F1 80 BF C0', FFFDx2),
2206 ('F1 80 BF FF', FFFDx2), ('F1 BF 80 00', FFFD+'\x00'),
2207 ('F1 BF 80 7F', FFFD+'\x7f'), ('F1 BF 80 C0', FFFDx2),
2208 ('F1 BF 80 FF', FFFDx2), ('F1 BF BF 00', FFFD+'\x00'),
2209 ('F1 BF BF 7F', FFFD+'\x7f'), ('F1 BF BF C0', FFFDx2),
2210 ('F1 BF BF FF', FFFDx2), ('F3 00', FFFD+'\x00'),
2211 ('F3 7F', FFFD+'\x7f'), ('F3 C0', FFFDx2), ('F3 FF', FFFDx2),
2212 ('F3 80 00', FFFD+'\x00'), ('F3 80 7F', FFFD+'\x7f'),
2213 ('F3 80 C0', FFFDx2), ('F3 80 FF', FFFDx2),
2214 ('F3 BF 00', FFFD+'\x00'), ('F3 BF 7F', FFFD+'\x7f'),
2215 ('F3 BF C0', FFFDx2), ('F3 BF FF', FFFDx2),
2216 ('F3 80 80 00', FFFD+'\x00'), ('F3 80 80 7F', FFFD+'\x7f'),
2217 ('F3 80 80 C0', FFFDx2), ('F3 80 80 FF', FFFDx2),
2218 ('F3 80 BF 00', FFFD+'\x00'), ('F3 80 BF 7F', FFFD+'\x7f'),
2219 ('F3 80 BF C0', FFFDx2), ('F3 80 BF FF', FFFDx2),
2220 ('F3 BF 80 00', FFFD+'\x00'), ('F3 BF 80 7F', FFFD+'\x7f'),
2221 ('F3 BF 80 C0', FFFDx2), ('F3 BF 80 FF', FFFDx2),

Callers

nothing calls this directly

Calls 2

fromhexMethod · 0.45

Tested by

no test coverage detected