From f4c3f0ab0f6b6a2d5cb9395936128fe3942e87e0 Mon Sep 17 00:00:00 2001 From: ntrifunovic Date: Sun, 20 Feb 2011 18:07:59 +0000 Subject: [PATCH] Fix for the bug ID: 3083640 - is_code_point_valid incorrectly returns false git-svn-id: http://svn.code.sf.net/p/utfcpp/code@117 a809a056-fc17-0410-9590-b4f493f8b08e Conflicts: v2_0/test_data/negative/utf8_invalid.txt --- source/utf8/core.h | 2 +- test_data/negative/utf8_invalid.txt | Bin 20334 -> 20010 bytes test_drivers/negative/negative.cpp | 10 ++++++---- 3 files changed, 7 insertions(+), 5 deletions(-) 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 abd16f7253bf7254ad1ae04cb5bee8d8c47e407a..ae83159328313d3ba57b4f51ccb96db3dbfd79f1 100755 GIT binary patch delta 17 ZcmaDik8#x;#tmJ*lh5l1PL}ug2LMY!2aW&$ delta 106 zcmZ2AhwrOV{H~;_u 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'; } }