Answers:
看看Markus Kuhn的UTF-8解码器功能和压力测试文件
您会发现许多UTF-8不规则的示例,包括寂寞的起始字节,丢失的连续字节,超长序列等。
在PHP中:
$examples = array(
'Valid ASCII' => "a",
'Valid 2 Octet Sequence' => "\xc3\xb1",
'Invalid 2 Octet Sequence' => "\xc3\x28",
'Invalid Sequence Identifier' => "\xa0\xa1",
'Valid 3 Octet Sequence' => "\xe2\x82\xa1",
'Invalid 3 Octet Sequence (in 2nd Octet)' => "\xe2\x28\xa1",
'Invalid 3 Octet Sequence (in 3rd Octet)' => "\xe2\x82\x28",
'Valid 4 Octet Sequence' => "\xf0\x90\x8c\xbc",
'Invalid 4 Octet Sequence (in 2nd Octet)' => "\xf0\x28\x8c\xbc",
'Invalid 4 Octet Sequence (in 3rd Octet)' => "\xf0\x90\x28\xbc",
'Invalid 4 Octet Sequence (in 4th Octet)' => "\xf0\x28\x8c\x28",
'Valid 5 Octet Sequence (but not Unicode!)' => "\xf8\xa1\xa1\xa1\xa1",
'Valid 6 Octet Sequence (but not Unicode!)' => "\xfc\xa1\xa1\xa1\xa1\xa1",
);
来自http://www.php.net/manual/zh/reference.pcre.pattern.modifiers.php#54805
格式错误的字节序列模式的思想可以从格式良好的字节序列表中获得。请参见Unicode标准6.2中的“ 表3-7。格式正确的UTF-8字节序列 ”。
Code Points First Byte Second Byte Third Byte Fourth Byte
U+0000 - U+007F 00 - 7F
U+0080 - U+07FF C2 - DF 80 - BF
U+0800 - U+0FFF E0 A0 - BF 80 - BF
U+1000 - U+CFFF E1 - EC 80 - BF 80 - BF
U+D000 - U+D7FF ED 80 - 9F 80 - BF
U+E000 - U+FFFF EE - EF 80 - BF 80 - BF
U+10000 - U+3FFFF F0 90 - BF 80 - BF 80 - BF
U+40000 - U+FFFFF F1 - F3 80 - BF 80 - BF 80 - BF
U+100000 - U+10FFFF F4 80 - 8F 80 - BF 80 - BF
以下是从U + 24B62生成的示例。我将它们用于错误报告:错误#65045 mb_convert_encoding破坏格式正确的字符
// U+24B62: "\xF0\xA4\xAD\xA2"
"\xF0\xA4\xAD" ."\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD\xA2"
"\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD"
在各种库中可以看到尾部字节范围([0x80,0xBF])的过度简化。
// U+0800 - U+0FFF
\xE0\x80\x80
// U+D000 - U+D7FF
\xED\xBF\xBF
// U+10000 - U+3FFFF
\xF0\x80\x80\x80
// U+100000 - U+10FFFF
\xF4\xBF\xBF\xBF