diff --git a/source/utf8/core.h b/source/utf8/core.h index ec709f1..268cf7c 100644 --- a/source/utf8/core.h +++ b/source/utf8/core.h @@ -92,7 +92,7 @@ namespace internal template inline bool is_code_point_valid(u32 cp) { - return (cp <= CODE_POINT_MAX && !is_surrogate(cp) && cp != 0xfffe && cp != 0xffff); + return (cp <= CODE_POINT_MAX && !is_surrogate(cp)); } template diff --git a/test_data/negative/utf8_invalid.txt b/test_data/negative/utf8_invalid.txt index abd16f7..ae83159 100755 Binary files a/test_data/negative/utf8_invalid.txt and b/test_data/negative/utf8_invalid.txt differ diff --git a/test_drivers/negative/negative.cpp b/test_drivers/negative/negative.cpp index 0497945..ea64cce 100644 --- a/test_drivers/negative/negative.cpp +++ b/test_drivers/negative/negative.cpp @@ -7,7 +7,7 @@ using namespace utf8; #include using namespace std; -const unsigned INVALID_LINES[] = { 75, 76, 82, 83, 84, 85, 93, 102, 103, 105, 106, 107, 108, 109, 110, 114, 115, 116, 117, 124, 125, 130, 135, 140, 145, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 169, 175, 176, 177, 207, 208, 209, 210, 211, 220, 221, 222, 223, 224, 232, 233, 234, 235, 236, 247, 248, 249, 250, 251, 252, 253, 257, 258, 259, 260, 261, 262, 263, 264, 268, 269}; +const unsigned INVALID_LINES[] = { 75, 76, 82, 83, 84, 85, 93, 102, 103, 105, 106, 107, 108, 109, 110, 114, 115, 116, 117, 124, 125, 130, 135, 140, 145, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 169, 175, 176, 177, 207, 208, 209, 210, 211, 220, 221, 222, 223, 224, 232, 233, 234, 235, 236, 247, 248, 249, 250, 251, 252, 253, 257, 258, 259, 260, 261, 262, 263, 264}; const unsigned* INVALID_LINES_END = INVALID_LINES + sizeof(INVALID_LINES)/sizeof(unsigned); int main(int argc, char** argv) @@ -35,10 +35,10 @@ int main(int argc, char** argv) line.push_back(byte); line_count++; - // Print out lines that contain invalid UTF-8 + bool expected_valid = (find(INVALID_LINES, INVALID_LINES_END, line_count) == INVALID_LINES_END); + // Print out lines that contain unexpected invalid UTF-8 if (!is_valid(line.begin(), line.end())) { - const unsigned* u = find(INVALID_LINES, INVALID_LINES_END, line_count); - if (u == INVALID_LINES_END) + if (expected_valid) cout << "Unexpected invalid utf-8 at line " << line_count << '\n'; // try fixing it: @@ -47,5 +47,7 @@ int main(int argc, char** argv) if (!is_valid(fixed_line.begin(), fixed_line.end())) cout << "replace_invalid() resulted in an invalid utf-8 at line " << line_count << '\n'; } + else if (!expected_valid) + cout << "Invalid utf-8 NOT detected at line " << line_count << '\n'; } }