com php-src: Fix mbstring support for ARMSCII-8: ext/mbstring/l ibmbfl/filters/mbfilter_armscii8.c ext/mbstring/libmbfl
/filters/unicode_table_armscii8.h ext/mbstring/libmbf l/mbfl/mbfl_consts.h
| From: | Alex Dowad | Date: | Mon, 02 Nov 2020 19:31:06 +0000 |
| Subject: | com php-src: Fix mbstring support for ARMSCII-8: ext/mbstring/l ibmbfl/filters/mbfilter_armscii8.c ext/mbstring/libmbfl /filters/unicode_table_armscii8.h ext/mbstring/libmbf l/mbfl/mbfl_consts.h |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-114019@lists.php.net to get a copy of this message | ||
Commit: 9f5a4b3bd939c6cee2a62eb636b657d8c09eb5ea
Author: Alex Dowad <alexinbeijing@gmail.com> Sun, 18 Oct 2020 17:49:57 +0200
Parents: be1a215538f931740a75e9f4ddd628bbc2a03a7c
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9f5a4b3bd939c6cee2a62eb636b657d8c09eb5ea
Log:
Fix mbstring support for ARMSCII-8
- Identify filter was completely wrong.
- Respect
mb_substitute_character rather than converting invalid bytes to
Unicode 0xFFFD (generic replacement character).
- Don't convert Unicode 0xFFFD to a valid ARMSCII-8 character.
- When converting ARMSCII-8 to ARMSCII-8, don't pass invalid bytes through
silently.
Changed paths:
M ext/mbstring/libmbfl/filters/mbfilter_armscii8.c
M ext/mbstring/libmbfl/filters/unicode_table_armscii8.h
M ext/mbstring/libmbfl/mbfl/mbfl_consts.h
Diff:
diff --git a/ext/mbstring/libmbfl/filters/mbfilter_armscii8.c
b/ext/mbstring/libmbfl/filters/mbfilter_armscii8.c
index e2fa8d86eab..55668fceb9c 100644
--- a/ext/mbstring/libmbfl/filters/mbfilter_armscii8.c
+++ b/ext/mbstring/libmbfl/filters/mbfilter_armscii8.c
@@ -73,63 +73,36 @@ const struct mbfl_convert_vtbl vtbl_armscii8_wchar = {
#define CK(statement) do { if ((statement) < 0) return (-1); } while (0)
-/*
- * armscii8 => wchar
- */
int mbfl_filt_conv_armscii8_wchar(int c, mbfl_convert_filter *filter)
{
int s;
- if (c >= 0 && c < armscii8_ucs_table_min) {
+ if (c < armscii8_ucs_table_min) {
s = c;
- } else if (c >= armscii8_ucs_table_min && c < 0x100) {
+ } else {
s = armscii8_ucs_table[c - armscii8_ucs_table_min];
- if (s <= 0) {
- s = c;
- s &= MBFL_WCSPLANE_MASK;
- s |= MBFL_WCSPLANE_ARMSCII8;
+ if (!s) {
+ s = c | MBFL_WCSGROUP_THROUGH;
}
- } else {
- s = c;
- s &= MBFL_WCSGROUP_MASK;
- s |= MBFL_WCSGROUP_THROUGH;
}
CK((*filter->output_function)(s, filter->data));
-
return c;
}
-/*
- * wchar => armscii8
- */
int mbfl_filt_conv_wchar_armscii8(int c, mbfl_convert_filter *filter)
{
-
- int s, n;
-
- if (c >= 0x28 && c < 0x30) {
- s = ucs_armscii8_table[c-0x28];
+ if (c >= 0x28 && c <= 0x2F) {
+ CK((*filter->output_function)(ucs_armscii8_table[c - 0x28], filter->data));
} else if (c < armscii8_ucs_table_min) {
- s = c;
+ CK((*filter->output_function)(c, filter->data));
} else {
- s = -1;
- n = armscii8_ucs_table_len-1;
- while (n >= 0) {
+ for (int n = 0; n < armscii8_ucs_table_len; n++) {
if (c == armscii8_ucs_table[n]) {
- s = armscii8_ucs_table_min + n;
- break;
+ CK((*filter->output_function)(armscii8_ucs_table_min + n, filter->data));
+ return c;
}
- n--;
- }
- if (s <= 0 && (c & ~MBFL_WCSPLANE_MASK) == MBFL_WCSPLANE_ARMSCII8) {
- s = c & MBFL_WCSPLANE_MASK;
}
- }
-
- if (s >= 0) {
- CK((*filter->output_function)(s, filter->data));
- } else {
CK(mbfl_filt_conv_illegal_output(c, filter));
}
@@ -138,9 +111,8 @@ int mbfl_filt_conv_wchar_armscii8(int c, mbfl_convert_filter *filter)
static int mbfl_filt_ident_armscii8(int c, mbfl_identify_filter *filter)
{
- if (c >= armscii8_ucs_table_min && c <= 0xff)
- filter->flag = 0;
- else
- filter->flag = 1; /* not it */
+ if (c >= armscii8_ucs_table_min && !armscii8_ucs_table[c - armscii8_ucs_table_min]) {
+ filter->flag = 1;
+ }
return c;
}
diff --git a/ext/mbstring/libmbfl/filters/unicode_table_armscii8.h
b/ext/mbstring/libmbfl/filters/unicode_table_armscii8.h
index abf89867eaa...6630148f259 100644
--- a/ext/mbstring/libmbfl/filters/unicode_table_armscii8.h
+++ b/ext/mbstring/libmbfl/filters/unicode_table_armscii8.h
@@ -27,8 +27,7 @@
/* ArmSCII-8 to Unicode table */
static const unsigned short armscii8_ucs_table[] = {
-/*0x00a0, 0x00a1, 0x0587, 0x0589, 0x0029, 0x0028, 0x00bb, 0x00ab,*/
-0x00a0, 0xfffd, 0x0587, 0x0589, 0x0029, 0x0028, 0x00bb, 0x00ab,
+0x00a0, 0x0000, 0x0587, 0x0589, 0x0029, 0x0028, 0x00bb, 0x00ab,
0x2014, 0x002e, 0x055d, 0x002c, 0x002d, 0x058a, 0x2026, 0x055c,
0x055b, 0x055e, 0x0531, 0x0561, 0x0532, 0x0562, 0x0533, 0x0563,
0x0534, 0x0564, 0x0535, 0x0565, 0x0536, 0x0566, 0x0537, 0x0567,
@@ -39,8 +38,7 @@ static const unsigned short armscii8_ucs_table[] = {
0x0548, 0x0578, 0x0549, 0x0579, 0x054a, 0x057a, 0x054b, 0x057b,
0x054c, 0x057c, 0x054d, 0x057d, 0x054e, 0x057e, 0x054f, 0x057f,
0x0550, 0x0580, 0x0551, 0x0581, 0x0552, 0x0582, 0x0553, 0x0583,
-/*0x0554, 0x0584, 0x0555, 0x0585, 0x0556, 0x0586, 0x055a, 0x00ff*/
-0x0554, 0x0584, 0x0555, 0x0585, 0x0556, 0x0586, 0x055a, 0xfffd
+0x0554, 0x0584, 0x0555, 0x0585, 0x0556, 0x0586, 0x055a, 0x0000
};
static const unsigned char ucs_armscii8_table[] = {
diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_consts.h b/ext/mbstring/libmbfl/mbfl/mbfl_consts.h
index a5a8765072f..dd37165ecf1 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfl_consts.h
+++ b/ext/mbstring/libmbfl/mbfl/mbfl_consts.h
@@ -61,7 +61,6 @@
#define MBFL_WCSPLANE_BIG5 0x70f40000 /* 2121h - 9898h */
#define MBFL_WCSPLANE_CNS11643 0x70f50000 /* 2121h - 9898h */
#define MBFL_WCSPLANE_UHC 0x70f60000 /* 8141h - fefeh */
-#define MBFL_WCSPLANE_ARMSCII8 0x70fb0000
#define MBFL_WCSPLANE_GB18030 0x70ff0000 /* a1a1h-e3329a35h */
#define MBFL_WCSGROUP_MASK 0xffffff
#define MBFL_WCSGROUP_UCS4MAX 0x70000000