diff options
Diffstat (limited to 'ext/mbstring')
-rw-r--r-- | ext/mbstring/README_PHP3-i18n-ja | 2 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/filters/mbfilter_utf8.c | 184 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/filters/mbfilter_utf8.h | 1 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c | 185 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/filters/unicode_table_jis2004.h | 2 | ||||
-rw-r--r-- | ext/mbstring/oniguruma/HISTORY | 4 | ||||
-rw-r--r-- | ext/mbstring/php_mbregex.c | 2 | ||||
-rw-r--r-- | ext/mbstring/tests/bug65045.phpt | 29 | ||||
-rw-r--r-- | ext/mbstring/tests/illformed_utf_sequences.phpt | 18 | ||||
-rw-r--r-- | ext/mbstring/tests/mb_http_output.phpt | 2 | ||||
-rw-r--r-- | ext/mbstring/tests/mb_str_functions_opt-parameter.phpt | 2 |
11 files changed, 223 insertions, 208 deletions
diff --git a/ext/mbstring/README_PHP3-i18n-ja b/ext/mbstring/README_PHP3-i18n-ja index cac00b82a..869fe3e49 100644 --- a/ext/mbstring/README_PHP3-i18n-ja +++ b/ext/mbstring/README_PHP3-i18n-ja @@ -408,7 +408,7 @@ o i18n.script_encoding - script encoding entering the script parser. Be aware that auto detection may fail under some conditions. - For best auto detection, add multibyte charactor at begining of + For best auto detection, add multibyte charactor at beginning of script. diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf8.c b/ext/mbstring/libmbfl/filters/mbfilter_utf8.c index fcee61053..553970034 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf8.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf8.c @@ -79,7 +79,7 @@ const struct mbfl_convert_vtbl vtbl_utf8_wchar = { mbfl_filt_conv_common_ctor, mbfl_filt_conv_common_dtor, mbfl_filt_conv_utf8_wchar, - mbfl_filt_conv_common_flush + mbfl_filt_conv_utf8_wchar_flush }; const struct mbfl_convert_vtbl vtbl_wchar_utf8 = { @@ -93,6 +93,17 @@ const struct mbfl_convert_vtbl vtbl_wchar_utf8 = { #define CK(statement) do { if ((statement) < 0) return (-1); } while (0) +int mbfl_filt_put_invalid_char(int c, mbfl_convert_filter *filter) +{ + int w; + w = c & MBFL_WCSGROUP_MASK; + w |= MBFL_WCSGROUP_THROUGH; + filter->status = 0; + filter->cache = 0; + CK((*filter->output_function)(w, filter->data)); +} + + /* * UTF-8 => wchar */ @@ -100,111 +111,104 @@ int mbfl_filt_conv_utf8_wchar(int c, mbfl_convert_filter *filter) { int s, c1, w = 0, flag = 0; - if (c < 0x80) { - if (filter->status != 0) { - w = (filter->cache & MBFL_WCSGROUP_MASK) | MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); - filter->status = 0; - filter->cache = 0; - } - if (c >= 0) { +retry: + switch (filter->status & 0xff) { + case 0x00: + if (c < 0x80) { CK((*filter->output_function)(c, filter->data)); + } else if (c >= 0xc2 && c <= 0xdf) { /* 2byte code first char: 0xc2-0xdf */ + filter->status = 0x10; + filter->cache = c & 0x1f; + } else if (c >= 0xe0 && c <= 0xef) { /* 3byte code first char: 0xe0-0xef */ + filter->status = 0x20; + filter->cache = c & 0xf; + } else if (c >= 0xf0 && c <= 0xf4) { /* 3byte code first char: 0xf0-0xf4 */ + filter->status = 0x30; + filter->cache = c & 0x7; + } else { + mbfl_filt_put_invalid_char(c, filter); } - } else if (c < 0xc0) { - int status = filter->status & 0xff; - switch (status) { - case 0x10: /* 2byte code 2nd char: 0x80-0xbf */ - case 0x21: /* 3byte code 3rd char: 0x80-0xbf */ - case 0x32: /* 4byte code 4th char: 0x80-0xbf */ - filter->status = 0; - s = filter->cache | (c & 0x3f); + break; + case 0x10: /* 2byte code 2nd char: 0x80-0xbf */ + case 0x21: /* 3byte code 3rd char: 0x80-0xbf */ + case 0x32: /* 4byte code 4th char: 0x80-0xbf */ + filter->status = 0; + if (c >= 0x80 && c <= 0xbf) { + s = (filter->cache<<6) | (c & 0x3f); filter->cache = 0; - if ((status == 0x10 && s >= 0x80) || - (status == 0x21 && s >= 0x800 && (s < 0xd800 || s > 0xdfff)) || - (status == 0x32 && s >= 0x10000 && s < 0x110000)) { - CK((*filter->output_function)(s, filter->data)); - } else { - w = s & MBFL_WCSGROUP_MASK; - flag = 1; - } - break; - case 0x20: /* 3byte code 2nd char: 0:0xa0-0xbf,D:0x80-9F,1-C,E-F:0x80-0x9f */ - s = filter->cache | ((c & 0x3f) << 6); - c1 = (s >> 12) & 0xf; - if ((c1 == 0x0 && c >= 0xa0) || - (c1 == 0xd && c < 0xa0) || - (c1 > 0x0 && c1 != 0xd)) { - filter->cache = s; - filter->status++; - } else { - w = s & MBFL_WCSGROUP_MASK; - flag = 1; - } - break; - case 0x31: /* 4byte code 3rd char: 0x80-0xbf */ - filter->cache |= ((c & 0x3f) << 6); - filter->status++; - break; - case 0x30: /* 4byte code 2nd char: 0:0x90-0xbf,1-3:0x80-0xbf,4:0x80-0x8f */ - s = filter->cache | ((c & 0x3f) << 12); - c1 = (s >> 18) & 0x7; - if ((c1 == 0x0 && c >= 0x90) || - (c1 > 0x0 && c1 < 0x4) || - (c1 == 0x4 && c < 0x90)) { - filter->cache = s; - filter->status++; - } else { - w = s & MBFL_WCSGROUP_MASK; - flag = 1; - } - break; - default: - w = c & MBFL_WCSGROUP_MASK; - flag = 1; - break; + CK((*filter->output_function)(s, filter->data)); + } else { + mbfl_filt_put_invalid_char(filter->cache, filter); + goto retry; } - } else if (c < 0xc2) { /* invalid: 0xc0,0xc1 */ - w = c & MBFL_WCSGROUP_MASK; - flag = 1; - } else if (c < 0xe0) { /* 2byte code first char: 0xc2-0xdf */ - if (filter->status == 0x0) { - filter->status = 0x10; - filter->cache = (c & 0x1f) << 6; + break; + case 0x20: /* 3byte code 2nd char: 0:0xa0-0xbf,D:0x80-9F,1-C,E-F:0x80-0x9f */ + s = (filter->cache<<6) | (c & 0x3f); + c1 = filter->cache & 0xf; + + if ((c >= 0x80 && c <= 0xbf) && + ((c1 == 0x0 && c >= 0xa0) || + (c1 == 0xd && c < 0xa0) || + (c1 > 0x0 && c1 != 0xd))) { + filter->cache = s; + filter->status++; } else { - w = c & MBFL_WCSGROUP_MASK; - flag = 1; + mbfl_filt_put_invalid_char(filter->cache, filter); + goto retry; } - } else if (c < 0xf0) { /* 3byte code first char: 0xe0-0xef */ - if (filter->status == 0x0) { - filter->status = 0x20; - filter->cache = (c & 0xf) << 12; + break; + case 0x30: /* 4byte code 2nd char: 0:0x90-0xbf,1-3:0x80-0xbf,4:0x80-0x8f */ + s = (filter->cache<<6) | (c & 0x3f); + c1 = filter->cache & 0x7; + + if ((c >= 0x80 && c <= 0xbf) && + ((c1 == 0x0 && c >= 0x90) || + (c1 == 0x4 && c < 0x90) || + (c1 > 0x0 && c1 != 0x4))) { + filter->cache = s; + filter->status++; } else { - w = c & MBFL_WCSGROUP_MASK; - flag = 1; + mbfl_filt_put_invalid_char(filter->cache, filter); + goto retry; } - } else if (c < 0xf5) { /* 4byte code first char: 0xf0-0xf4 */ - if (filter->status == 0x0) { - filter->status = 0x30; - filter->cache = (c & 0x7) << 18; + break; + case 0x31: /* 4byte code 3rd char: 0x80-0xbf */ + if (c >= 0x80 && c <= 0xbf) { + filter->cache = (filter->cache<<6) | (c & 0x3f); + filter->status++; } else { - w = c & MBFL_WCSGROUP_MASK; - flag = 1; + mbfl_filt_put_invalid_char(filter->cache, filter); + goto retry; } - } else { - w = c & MBFL_WCSGROUP_MASK; - flag = 1; - } - - if (flag) { - w |= MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + break; + default: filter->status = 0; - filter->cache = 0; + break; } return c; } +int mbfl_filt_conv_utf8_wchar_flush(mbfl_convert_filter *filter) +{ + int status, cache; + + status = filter->status; + cache = filter->cache; + + filter->status = 0; + filter->cache = 0; + + if (status != 0) { + mbfl_filt_put_invalid_char(cache, filter); + } + + if (filter->flush_function != NULL) { + (*filter->flush_function)(filter->data); + } + return 0; +} + /* * wchar => UTF-8 */ diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf8.h b/ext/mbstring/libmbfl/filters/mbfilter_utf8.h index 07bf65502..970ace646 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf8.h +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf8.h @@ -37,5 +37,6 @@ extern const struct mbfl_convert_vtbl vtbl_wchar_utf8; int mbfl_filt_conv_utf8_wchar(int c, mbfl_convert_filter *filter); int mbfl_filt_conv_wchar_utf8(int c, mbfl_convert_filter *filter); +int mbfl_filt_conv_utf8_wchar_flush(mbfl_convert_filter *filter); #endif /* MBFL_MBFILTER_UTF8_H */ diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c b/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c index 62feca40b..f9b643c17 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c @@ -37,6 +37,7 @@ #include "mbfilter_sjis_mobile.h" extern int mbfl_filt_ident_utf8(int c, mbfl_identify_filter *filter); +extern int mbfl_filt_conv_utf8_wchar_flush(mbfl_convert_filter *filter); extern const unsigned char mblen_table_utf8[]; @@ -115,7 +116,7 @@ const struct mbfl_convert_vtbl vtbl_utf8_docomo_wchar = { mbfl_filt_conv_common_ctor, mbfl_filt_conv_common_dtor, mbfl_filt_conv_utf8_mobile_wchar, - mbfl_filt_conv_common_flush + mbfl_filt_conv_utf8_wchar_flush }; const struct mbfl_convert_vtbl vtbl_wchar_utf8_docomo = { @@ -133,7 +134,7 @@ const struct mbfl_convert_vtbl vtbl_utf8_kddi_a_wchar = { mbfl_filt_conv_common_ctor, mbfl_filt_conv_common_dtor, mbfl_filt_conv_utf8_mobile_wchar, - mbfl_filt_conv_common_flush + mbfl_filt_conv_utf8_wchar_flush }; const struct mbfl_convert_vtbl vtbl_wchar_utf8_kddi_a = { @@ -151,7 +152,7 @@ const struct mbfl_convert_vtbl vtbl_utf8_kddi_b_wchar = { mbfl_filt_conv_common_ctor, mbfl_filt_conv_common_dtor, mbfl_filt_conv_utf8_mobile_wchar, - mbfl_filt_conv_common_flush + mbfl_filt_conv_utf8_wchar_flush }; const struct mbfl_convert_vtbl vtbl_wchar_utf8_kddi_b = { @@ -169,7 +170,7 @@ const struct mbfl_convert_vtbl vtbl_utf8_sb_wchar = { mbfl_filt_conv_common_ctor, mbfl_filt_conv_common_dtor, mbfl_filt_conv_utf8_mobile_wchar, - mbfl_filt_conv_common_flush + mbfl_filt_conv_utf8_wchar_flush }; const struct mbfl_convert_vtbl vtbl_wchar_utf8_sb = { @@ -191,119 +192,97 @@ int mbfl_filt_conv_utf8_mobile_wchar(int c, mbfl_convert_filter *filter) int s, w = 0, flag = 0; int s1 = 0, c1 = 0, snd = 0; - if (c < 0x80) { - if (c >= 0) { +retry: + switch (filter->status & 0xff) { + case 0x00: + if (c < 0x80) { CK((*filter->output_function)(c, filter->data)); + } else if (c >= 0xc2 && c <= 0xdf) { /* 2byte code first char: 0xc2-0xdf */ + filter->status = 0x10; + filter->cache = c & 0x1f; + } else if (c >= 0xe0 && c <= 0xef) { /* 3byte code first char: 0xe0-0xef */ + filter->status = 0x20; + filter->cache = c & 0xf; + } else if (c >= 0xf0 && c <= 0xf4) { /* 3byte code first char: 0xf0-0xf4 */ + filter->status = 0x30; + filter->cache = c & 0x7; + } else { + mbfl_filt_put_invalid_char(c, filter); } + break; + case 0x10: /* 2byte code 2nd char: 0x80-0xbf */ + case 0x21: /* 3byte code 3rd char: 0x80-0xbf */ + case 0x32: /* 4byte code 4th char: 0x80-0xbf */ filter->status = 0; - } else if (c < 0xc0) { - int status = filter->status & 0xff; - switch (status) { - case 0x10: /* 2byte code 2nd char: 0x80-0xbf */ - case 0x21: /* 3byte code 3rd char: 0x80-0xbf */ - case 0x32: /* 4byte code 4th char: 0x80-0xbf */ - filter->status = 0; - s = filter->cache | (c & 0x3f); + if (c >= 0x80 && c <= 0xbf) { + s = (filter->cache<<6) | (c & 0x3f); filter->cache = 0; - if ((status == 0x10 && s >= 0x80) || - (status == 0x21 && s >= 0x800 && (s < 0xd800 || s > 0xdfff)) || - (status == 0x32 && s >= 0x10000 && s < 0x110000)) { - - if (filter->from->no_encoding == mbfl_no_encoding_utf8_docomo && - mbfilter_conv_r_map_tbl(s, &s1, mbfl_docomo2uni_pua, 4) > 0) { - s = mbfilter_sjis_emoji_docomo2unicode(s1, &snd); - } else if (filter->from->no_encoding == mbfl_no_encoding_utf8_kddi_a && - mbfilter_conv_r_map_tbl(s, &s1, mbfl_kddi2uni_pua, 7) > 0) { - s = mbfilter_sjis_emoji_kddi2unicode(s1, &snd); - } else if (filter->from->no_encoding == mbfl_no_encoding_utf8_kddi_b && - mbfilter_conv_r_map_tbl(s, &s1, mbfl_kddi2uni_pua_b, 8) > 0) { - s = mbfilter_sjis_emoji_kddi2unicode(s1, &snd); - } else if (filter->from->no_encoding == mbfl_no_encoding_utf8_sb && - mbfilter_conv_r_map_tbl(s, &s1, mbfl_sb2uni_pua, 6) > 0) { - s = mbfilter_sjis_emoji_sb2unicode(s1, &snd); - } - - if (snd > 0) { - CK((*filter->output_function)(snd, filter->data)); - } - CK((*filter->output_function)(s, filter->data)); - } else { - w = s & MBFL_WCSGROUP_MASK; - flag = 1; - } - break; - case 0x20: /* 3byte code 2nd char: 0:0xa0-0xbf,D:0x80-9F,1-C,E-F:0x80-0x9f */ - s = filter->cache | ((c & 0x3f) << 6); - c1 = (s >> 12) & 0xf; - if ((c1 == 0x0 && c >= 0xa0) || - (c1 == 0xd && c < 0xa0) || - (c1 > 0x0 && c1 != 0xd)) { - filter->cache = s; - filter->status++; - } else { - w = s & MBFL_WCSGROUP_MASK; - flag = 1; + + if (filter->from->no_encoding == mbfl_no_encoding_utf8_docomo && + mbfilter_conv_r_map_tbl(s, &s1, mbfl_docomo2uni_pua, 4) > 0) { + s = mbfilter_sjis_emoji_docomo2unicode(s1, &snd); + } else if (filter->from->no_encoding == mbfl_no_encoding_utf8_kddi_a && + mbfilter_conv_r_map_tbl(s, &s1, mbfl_kddi2uni_pua, 7) > 0) { + s = mbfilter_sjis_emoji_kddi2unicode(s1, &snd); + } else if (filter->from->no_encoding == mbfl_no_encoding_utf8_kddi_b && + mbfilter_conv_r_map_tbl(s, &s1, mbfl_kddi2uni_pua_b, 8) > 0) { + s = mbfilter_sjis_emoji_kddi2unicode(s1, &snd); + } else if (filter->from->no_encoding == mbfl_no_encoding_utf8_sb && + mbfilter_conv_r_map_tbl(s, &s1, mbfl_sb2uni_pua, 6) > 0) { + s = mbfilter_sjis_emoji_sb2unicode(s1, &snd); } - break; - case 0x31: /* 4byte code 3rd char: 0x80-0xbf */ - filter->cache |= ((c & 0x3f) << 6); - filter->status++; - break; - case 0x30: /* 4byte code 2nd char: 0:0x90-0xbf,1-3:0x80-0xbf,4:0x80-0x8f */ - s = filter->cache | ((c & 0x3f) << 12); - c1 = (s >> 18) & 0x7; - if ((c1 == 0x0 && c >= 0x90) || - (c1 > 0x0 && c1 < 0x4) || - (c1 == 0x4 && c < 0x90)) { - filter->cache = s; - filter->status++; - } else { - w = s & MBFL_WCSGROUP_MASK; - flag = 1; + + if (snd > 0) { + CK((*filter->output_function)(snd, filter->data)); } - break; - default: - w = c & MBFL_WCSGROUP_MASK; - flag = 1; - break; + CK((*filter->output_function)(s, filter->data)); + } else { + mbfl_filt_put_invalid_char(filter->cache, filter); + goto retry; } - } else if (c < 0xc2) { /* invalid: 0xc0,0xc1 */ - w = c & MBFL_WCSGROUP_MASK; - flag = 1; - } else if (c < 0xe0) { /* 2byte code first char: 0xc2-0xdf */ - if (filter->status == 0x0) { - filter->status = 0x10; - filter->cache = (c & 0x1f) << 6; + break; + case 0x20: /* 3byte code 2nd char: 0:0xa0-0xbf,D:0x80-9F,1-C,E-F:0x80-0x9f */ + s = (filter->cache<<6) | (c & 0x3f); + c1 = filter->cache & 0xf; + + if ((c >= 0x80 && c <= 0xbf) && + ((c1 == 0x0 && c >= 0xa0) || + (c1 == 0xd && c < 0xa0) || + (c1 > 0x0 && c1 != 0xd))) { + filter->cache = s; + filter->status++; } else { - w = c & MBFL_WCSGROUP_MASK; - flag = 1; + mbfl_filt_put_invalid_char(filter->cache, filter); + goto retry; } - } else if (c < 0xf0) { /* 3byte code first char: 0xe0-0xef */ - if (filter->status == 0x0) { - filter->status = 0x20; - filter->cache = (c & 0xf) << 12; + break; + case 0x30: /* 4byte code 2nd char: 0:0x90-0xbf,1-3:0x80-0xbf,4:0x80-0x8f */ + s = (filter->cache<<6) | (c & 0x3f); + c1 = filter->cache & 0x7; + + if ((c >= 0x80 && c <= 0xbf) && + ((c1 == 0x0 && c >= 0x90) || + (c1 == 0x4 && c < 0x90) || + (c1 > 0x0 && c1 != 0x4))) { + filter->cache = s; + filter->status++; } else { - w = c & MBFL_WCSGROUP_MASK; - flag = 1; + mbfl_filt_put_invalid_char(filter->cache, filter); + goto retry; } - } else if (c < 0xf5) { /* 4byte code first char: 0xf0-0xf4 */ - if (filter->status == 0x0) { - filter->status = 0x30; - filter->cache = (c & 0x7) << 18; + break; + case 0x31: /* 4byte code 3rd char: 0x80-0xbf */ + if (c >= 0x80 && c <= 0xbf) { + filter->cache = (filter->cache<<6) | (c & 0x3f); + filter->status++; } else { - w = c & MBFL_WCSGROUP_MASK; - flag = 1; + mbfl_filt_put_invalid_char(filter->cache, filter); + goto retry; } - } else { - w = c & MBFL_WCSGROUP_MASK; - flag = 1; - } - - if (flag) { - w |= MBFL_WCSGROUP_THROUGH; - CK((*filter->output_function)(w, filter->data)); + break; + default: filter->status = 0; - filter->cache = 0; + break; } return c; diff --git a/ext/mbstring/libmbfl/filters/unicode_table_jis2004.h b/ext/mbstring/libmbfl/filters/unicode_table_jis2004.h index 5ae282e91..cb6c445e7 100644 --- a/ext/mbstring/libmbfl/filters/unicode_table_jis2004.h +++ b/ext/mbstring/libmbfl/filters/unicode_table_jis2004.h @@ -4643,7 +4643,7 @@ static const int ucs_r2_jisx0213_min = 0xFA0F; static const int ucs_r2_jisx0213_max = 0xFA6A; /* - CJK Compatibility Ideographs: U+F900 - U+FAFF (seperate mapping for U+F9XX) + CJK Compatibility Ideographs: U+F900 - U+FAFF (separate mapping for U+F9XX) */ static const unsigned short ucs_r2b_jisx0213_cmap_key[] = { 0xf91d,0xf928,0xf929,0xf936,0xf970,0xf9d0,0xf9dc}; diff --git a/ext/mbstring/oniguruma/HISTORY b/ext/mbstring/oniguruma/HISTORY index a1debefa4..647a46090 100644 --- a/ext/mbstring/oniguruma/HISTORY +++ b/ext/mbstring/oniguruma/HISTORY @@ -673,7 +673,7 @@ History 2004/10/18: [impl] (thanks Imai Yasumasa) enclose #include <sys/types.h> by #ifndef __BORLANDC__. 2004/10/18: [bug] (thanks Imai Yasumasa) - memory acess violation in select_opt_exact_info(). + memory access violation in select_opt_exact_info(). 2004/09/25: [dist] fix doc/API and doc/API.ja. 2004/09/25: [bug] fix OP_SEMI_END_BUF process in match_at() for the case USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE @@ -1607,7 +1607,7 @@ History 2003/01/31: [impl] rename TTRANS() to TOLOWER(). 2003/01/30: [bug] .c.o --> .c.obj in win32\Makefile. 2003/01/30: [impl] add -DNOT_RUBY to Makefile.in. - NOT_RUBY is refered in regint.h for escape double + NOT_RUBY is referred in regint.h for escape double including config.h. 2003/01/30: [impl] when string hasn't case ambiguity, don't compile to ignore case opcode. diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index 145ee0c13..607921ebb 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -648,7 +648,7 @@ _php_mb_regex_init_options(const char *parg, int narg, OnigOptionType *option, O /* }}} */ /* - * php funcions + * php functions */ /* {{{ proto string mb_regex_encoding([string encoding]) diff --git a/ext/mbstring/tests/bug65045.phpt b/ext/mbstring/tests/bug65045.phpt new file mode 100644 index 000000000..03a090ded --- /dev/null +++ b/ext/mbstring/tests/bug65045.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #65045: mb_convert_encoding breaks well-formed character +--SKIPIF-- +<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?> +--FILE-- +<?php + +//declare(encoding = 'UTF-8'); +mb_internal_encoding('UTF-8'); + +$str = "\xF0\xA4\xAD". "\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD\xA2"; +$expected = "\xEF\xBF\xBD"."\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD\xA2"; + +$str2 = "\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD"; +$expected2 = "\xF0\xA4\xAD\xA2"."\xF0\xA4\xAD\xA2"."\xEF\xBF\xBD"; + +mb_substitute_character(0xFFFD); +var_dump( + $expected === htmlspecialchars_decode(htmlspecialchars($str, ENT_SUBSTITUTE, 'UTF-8')), + $expected2 === htmlspecialchars_decode(htmlspecialchars($str2, ENT_SUBSTITUTE, 'UTF-8')), + $expected === mb_convert_encoding($str, 'UTF-8', 'UTF-8'), + $expected2 === mb_convert_encoding($str2, 'UTF-8', 'UTF-8') +); + +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true)
\ No newline at end of file diff --git a/ext/mbstring/tests/illformed_utf_sequences.phpt b/ext/mbstring/tests/illformed_utf_sequences.phpt index b5b9d94db..378b956d6 100644 --- a/ext/mbstring/tests/illformed_utf_sequences.phpt +++ b/ext/mbstring/tests/illformed_utf_sequences.phpt @@ -25,28 +25,28 @@ var_dump(chk_enc("\x31\x32\x33", 0)); var_dump(chk_enc("\x41\x42\x43", 0)); var_dump(chk_enc("\xc0\xb1\xc0\xb2\xc0\xb3", 6)); var_dump(chk_enc("\xc1\x81\xc1\x82\xc1\x83", 6)); -var_dump(chk_enc("\xe0\x80\xb1\xe0\x80\xb2\xe0\x80\xb3", 6)); -var_dump(chk_enc("\xe0\x81\x81\xe0\x81\x82\xe0\x81\x83", 6)); -var_dump(chk_enc("\xf0\x80\x80\xb1\xf0\x80\x80\xb2\xf0\x80\x80\xb3", 9)); -var_dump(chk_enc("\xf0\x80\x81\x81\xf0\x80\x81\x82\xf0\x81\x83", 8)); +var_dump(chk_enc("\xe0\x80\xb1\xe0\x80\xb2\xe0\x80\xb3", 9)); +var_dump(chk_enc("\xe0\x81\x81\xe0\x81\x82\xe0\x81\x83", 9)); +var_dump(chk_enc("\xf0\x80\x80\xb1\xf0\x80\x80\xb2\xf0\x80\x80\xb3", 12)); +var_dump(chk_enc("\xf0\x80\x81\x81\xf0\x80\x81\x82\xf0\x81\x83", 11)); var_dump(chk_enc("\xf8\x80\x80\x80\xb1\xf8\x80\x80\x80\xb2\xf8\x80\x80\x80\xb3", 15)); var_dump(chk_enc("\xf8\x80\x80\x81\x81\xf8\x80\x80\x81\x82\xf8\x80\x80\x81\x83", 15)); var_dump(chk_enc("\xfc\x80\x80\x80\x80\xb1\xfc\x80\x80\x80\x80\xb2\xfc\x80\x80\x80\x80\xb3", 18)); var_dump(chk_enc("\xfc\x80\x80\x80\x81\x81\xfc\x80\x80\x80\x81\x82\xfc\x80\x80\x80\x81\x83", 18)); var_dump(chk_enc("\xc2\xa2\xc2\xa3\xc2\xa5", 0)); -var_dump(chk_enc("\xe0\x82\xa2\xe0\x82\xa3\xe0\x82\xa5", 6)); -var_dump(chk_enc("\xf0\x80\x82\xa2\xf0\x80\x82\xa3\xf0\x80\x82\xa5", 9)); +var_dump(chk_enc("\xe0\x82\xa2\xe0\x82\xa3\xe0\x82\xa5", 9)); +var_dump(chk_enc("\xf0\x80\x82\xa2\xf0\x80\x82\xa3\xf0\x80\x82\xa5", 12)); var_dump(chk_enc("\xf8\x80\x80\x82\xa2\xf8\x80\x80\x82\xa3\xf8\x80\x80\x82\xa5", 15)); var_dump(chk_enc("\xfc\x80\x80\x80\x82\xa2\xfc\x80\x80\x80\x82\xa3\xfc\x80\x80\x80\x82\xa5", 18)); var_dump(chk_enc("\xc1\xbf", 2)); var_dump(chk_enc("\xc2\x80", 0)); var_dump(chk_enc("\xdf\xbf", 0)); -var_dump(chk_enc("\xe0\x9f\xff", 2)); +var_dump(chk_enc("\xe0\x9f\xff", 3)); var_dump(chk_enc("\xe0\xa0\x80", 2)); var_dump(chk_enc("\xef\xbf\xbf", 0)); -var_dump(chk_enc("\xf0\x8f\xbf\xbf", 3)); +var_dump(chk_enc("\xf0\x8f\xbf\xbf", 4)); var_dump(chk_enc("\xf0\x90\x80\x80", 0)); var_dump(chk_enc("\xf7\xbf\xbf\xbf", 4)); var_dump(chk_enc("\xf8\x87\xbf\xbf\xbf", 5)); @@ -61,7 +61,7 @@ echo "UTF-8 and surrogates area\n"; $out = ''; $cnt = 0; for ($i = 0xd7ff; $i <= 0xe000; ++$i) { - $s = chk_enc(pack('C3', 0xe0 | ($i >> 12), 0x80 | ($i >> 6) & 0x3f, 0x80 | $i & 0x3f), 2); + $s = chk_enc(pack('C3', 0xe0 | ($i >> 12), 0x80 | ($i >> 6) & 0x3f, 0x80 | $i & 0x3f), 3); if ($s === false) { $cnt++; } else { diff --git a/ext/mbstring/tests/mb_http_output.phpt b/ext/mbstring/tests/mb_http_output.phpt index 7fb3335fe..6f149bfc9 100644 --- a/ext/mbstring/tests/mb_http_output.phpt +++ b/ext/mbstring/tests/mb_http_output.phpt @@ -4,7 +4,7 @@ mb_http_output() <?php extension_loaded('mbstring') or die('skip mbstring not available'); ?> --FILE-- <?php -//TODO: Add more encoding. Wrong paramter type test. +//TODO: Add more encoding. Wrong parameter type test. //$debug = true; ini_set('include_path', dirname(__FILE__)); include_once('common.inc'); diff --git a/ext/mbstring/tests/mb_str_functions_opt-parameter.phpt b/ext/mbstring/tests/mb_str_functions_opt-parameter.phpt index 5fb642f9b..6219e585e 100644 --- a/ext/mbstring/tests/mb_str_functions_opt-parameter.phpt +++ b/ext/mbstring/tests/mb_str_functions_opt-parameter.phpt @@ -1,5 +1,7 @@ --TEST-- Optional long parameter might be null +--SKIPIF-- +<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?> --FILE-- <?php echo mb_strpos('abb', 'b', null, 'UTF-8') . "\n"; |