https://git.reactos.org/?p=reactos.git;a=commitdiff;h=17e9dcc9224b7773148c0…
commit 17e9dcc9224b7773148c015f6b4d916e4478272b
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Wed Jul 5 12:01:42 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Wed Jul 5 12:01:42 2023 +0900
[RTL][ADVAPI32_APITEST] RtlIsTextUnicode: Don't change weight unless lead-byte
flag (#5396)
- Fix the garbled characters (a.k.a. mojibake) in some Japanese text files.
- weight will remain 3 unless IS_TEXT_UNICODE_DBCS_LEADBYTE flag is set.
- Strengthen advapi32_apitest IsTextUnicode testcase.
CORE-19016
---
modules/rostests/apitests/advapi32/IsTextUnicode.c | 30 ++++++++++++++++++++--
sdk/lib/rtl/unicode.c | 5 ++--
2 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/modules/rostests/apitests/advapi32/IsTextUnicode.c
b/modules/rostests/apitests/advapi32/IsTextUnicode.c
index 404ab69d07d..d3f9f3dfcb5 100644
--- a/modules/rostests/apitests/advapi32/IsTextUnicode.c
+++ b/modules/rostests/apitests/advapi32/IsTextUnicode.c
@@ -4,6 +4,7 @@
* PURPOSE: Tests for (Rtl)IsTextUnicode.
* PROGRAMMERS: Hermes Belusca-Maito
* Dmitry Chapyshev
+ * Katayama Hirofumi MZ
*/
#include "precomp.h"
@@ -128,6 +129,9 @@ START_TEST(IsTextUnicode)
};
const char japanese_with_lead[] = "ABC" "\x83\x40"
"D";
+ const char japanese_sjis[] =
"\x93\xFA\x96\x7B\x8C\xEA\x31\x32\x33\x93\xFA\x96\x7B\x8C\xEA";
+ const char japanese_utf8[] =
"\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E\x31\x32\x33\xE6\x97\xA5"
+ "\xE6\x9C\xAC\xE8\xAA\x9E";
const char simplfied_chinese_with_lead[] = "ABC" "\xC5\xC5"
"D";
const char korean_with_lead[] = "ABC" "\xBF\xAD" "D";
const char traditional_chinese_with_lead[] = "ABC" "\xB1\xC1"
"D";
@@ -149,8 +153,30 @@ START_TEST(IsTextUnicode)
SetupLocale(932, 932, -1);
Result = IS_TEXT_UNICODE_DBCS_LEADBYTE;
- ok(!IsTextUnicode(japanese_with_lead, sizeof(japanese_with_lead), &Result),
"IsTextUnicode() returned TRUE, expected FALSE\n");
- ok(Result == IS_TEXT_UNICODE_DBCS_LEADBYTE, "Result returned 0x%x, expected
0x%x\n", Result, IS_TEXT_UNICODE_DBCS_LEADBYTE);
+ ok_int(IsTextUnicode(japanese_with_lead, sizeof(japanese_with_lead), &Result),
FALSE);
+ ok_int(Result, IS_TEXT_UNICODE_DBCS_LEADBYTE);
+
+ ok_int(IsTextUnicode(japanese_sjis, sizeof(japanese_sjis) - 1, NULL), FALSE);
+
+ Result = IS_TEXT_UNICODE_STATISTICS | IS_TEXT_UNICODE_REVERSE_STATISTICS;
+ ok_int(IsTextUnicode(japanese_sjis, sizeof(japanese_sjis) - 1, &Result), FALSE);
+ ok_int(Result, 0);
+
+ Result = IS_TEXT_UNICODE_STATISTICS | IS_TEXT_UNICODE_REVERSE_STATISTICS |
+ IS_TEXT_UNICODE_DBCS_LEADBYTE;
+ ok_int(IsTextUnicode(japanese_sjis, sizeof(japanese_sjis) - 1, &Result), FALSE);
+ ok_int(Result, (IS_TEXT_UNICODE_DBCS_LEADBYTE |
IS_TEXT_UNICODE_REVERSE_STATISTICS));
+
+ ok_int(IsTextUnicode(japanese_utf8, sizeof(japanese_utf8) - 1, NULL), FALSE);
+
+ Result = IS_TEXT_UNICODE_STATISTICS | IS_TEXT_UNICODE_REVERSE_STATISTICS;
+ ok_int(IsTextUnicode(japanese_utf8, sizeof(japanese_utf8) - 1, &Result), FALSE);
+ ok_int(Result, 0);
+
+ Result = IS_TEXT_UNICODE_STATISTICS | IS_TEXT_UNICODE_REVERSE_STATISTICS |
+ IS_TEXT_UNICODE_DBCS_LEADBYTE;
+ ok_int(IsTextUnicode(japanese_utf8, sizeof(japanese_utf8) - 1, &Result), FALSE);
+ ok_int(Result, (IS_TEXT_UNICODE_DBCS_LEADBYTE | IS_TEXT_UNICODE_STATISTICS));
/* Simplified Chinese */
SetupLocale(936, 936, -1);
diff --git a/sdk/lib/rtl/unicode.c b/sdk/lib/rtl/unicode.c
index 8c7248db155..c29dfa4f3b8 100644
--- a/sdk/lib/rtl/unicode.c
+++ b/sdk/lib/rtl/unicode.c
@@ -1356,7 +1356,7 @@ RtlIsTextUnicode(CONST VOID* buf, INT len, INT* pf)
}
}
- if (NlsMbCodePageTag)
+ if (NlsMbCodePageTag && pf && (*pf &
IS_TEXT_UNICODE_DBCS_LEADBYTE))
{
for (i = 0; i < len; i++)
{
@@ -1378,8 +1378,7 @@ RtlIsTextUnicode(CONST VOID* buf, INT len, INT* pf)
else
weight = 1;
- if (pf && (*pf & IS_TEXT_UNICODE_DBCS_LEADBYTE))
- out_flags |= IS_TEXT_UNICODE_DBCS_LEADBYTE;
+ out_flags |= IS_TEXT_UNICODE_DBCS_LEADBYTE;
}
}