Index: ext/mbstring/mb_gpc.c =================================================================== RCS file: /repository/php-src/ext/mbstring/mb_gpc.c,v retrieving revision 1.17 diff -u -r1.17 mb_gpc.c --- ext/mbstring/mb_gpc.c 3 Aug 2005 14:07:24 -0000 1.17 +++ ext/mbstring/mb_gpc.c 24 Dec 2005 13:01:46 -0000 @@ -266,7 +266,7 @@ } else { /* auto detect */ from_encoding = mbfl_no_encoding_invalid; - identd = mbfl_encoding_detector_new((enum mbfl_no_encoding *)info->from_encodings, info->num_from_encodings); + identd = mbfl_encoding_detector_new((enum mbfl_no_encoding *)info->from_encodings, info->num_from_encodings, MBSTRG(strict_detection)); if (identd) { n = 0; while (n < num) { Index: ext/mbstring/mbstring.c =================================================================== RCS file: /repository/php-src/ext/mbstring/mbstring.c,v retrieving revision 1.224.2.9 diff -u -r1.224.2.9 mbstring.c --- ext/mbstring/mbstring.c 23 Dec 2005 11:15:16 -0000 1.224.2.9 +++ ext/mbstring/mbstring.c 24 Dec 2005 13:01:47 -0000 @@ -734,6 +734,9 @@ STD_PHP_INI_BOOLEAN("mbstring.encoding_translation", "0", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdate_mbstring_encoding_translation, encoding_translation, zend_mbstring_globals, mbstring_globals) + + STD_PHP_INI_BOOLEAN("mbstring.strict_detection", "0", + PHP_INI_ALL, OnUpdateLong, strict_detection, zend_mbstring_globals, mbstring_globals) PHP_INI_END() /* }}} */ @@ -769,6 +772,7 @@ MBSTRG(current_filter_illegal_substchar) = 0x3f; /* '?' */ MBSTRG(func_overload) = 0; MBSTRG(encoding_translation) = 0; + MBSTRG(strict_detection) = 0; pglobals->outconv = NULL; #if HAVE_MBREGEX _php_mb_regex_globals_ctor(pglobals TSRMLS_CC); @@ -2022,7 +2026,7 @@ string.no_encoding = from_encoding; } else if (size > 1) { /* auto detect */ - from_encoding = mbfl_identify_encoding_no(&string, list, size); + from_encoding = mbfl_identify_encoding_no(&string, list, size, MBSTRG(strict_detection)); if (from_encoding != mbfl_no_encoding_invalid) { string.no_encoding = from_encoding; } else { @@ -2214,7 +2218,7 @@ mbfl_string string; const char *ret; enum mbfl_no_encoding *elist; - int size, *list, strict = 0; + int size, *list, strict; if (ZEND_NUM_ARGS() == 1) { if (zend_get_parameters_ex(1, &arg_str) == FAILURE) { @@ -2264,6 +2268,9 @@ convert_to_long_ex(arg_strict); strict = Z_LVAL_PP(arg_strict); } + else { + strict = MBSTRG(strict_detection); + } if (size > 0 && list != NULL) { elist = list; @@ -2555,7 +2562,7 @@ stack_max = PHP_MBSTR_STACK_BLOCK_SIZE; stack = (zval ***)safe_emalloc(stack_max, sizeof(zval **), 0); stack_level = 0; - identd = mbfl_encoding_detector_new(elist, elistsz); + identd = mbfl_encoding_detector_new(elist, elistsz, MBSTRG(strict_detection)); if (identd != NULL) { n = 2; while (n < argc || stack_level > 0) { @@ -3174,7 +3181,7 @@ orig_str.no_encoding = MBSTRG(current_internal_encoding); if (orig_str.no_encoding == mbfl_no_encoding_invalid || orig_str.no_encoding == mbfl_no_encoding_pass) { - orig_str.no_encoding = mbfl_identify_encoding_no(&orig_str, MBSTRG(current_detect_order_list), MBSTRG(current_detect_order_list_size)); + orig_str.no_encoding = mbfl_identify_encoding_no(&orig_str, MBSTRG(current_detect_order_list), MBSTRG(current_detect_order_list_size), MBSTRG(strict_detection)); } pstr = mbfl_mime_header_encode(&orig_str, &conv_str, tran_cs, head_enc, "\n", sizeof("Subject: [PHP-jp nnnnnnnn]")); if (pstr != NULL) { @@ -3194,7 +3201,7 @@ if (orig_str.no_encoding == mbfl_no_encoding_invalid || orig_str.no_encoding == mbfl_no_encoding_pass) { - orig_str.no_encoding = mbfl_identify_encoding_no(&orig_str, MBSTRG(current_detect_order_list), MBSTRG(current_detect_order_list_size)); + orig_str.no_encoding = mbfl_identify_encoding_no(&orig_str, MBSTRG(current_detect_order_list), MBSTRG(current_detect_order_list_size), MBSTRG(strict_detection)); } pstr = NULL; @@ -3571,7 +3578,7 @@ mbfl_string_init(&string); string.no_language = MBSTRG(current_language); - identd = mbfl_encoding_detector_new(elist, size); + identd = mbfl_encoding_detector_new(elist, size, MBSTRG(strict_detection)); if (identd) { int n = 0; Index: ext/mbstring/mbstring.h =================================================================== RCS file: /repository/php-src/ext/mbstring/mbstring.h,v retrieving revision 1.66 diff -u -r1.66 mbstring.h --- ext/mbstring/mbstring.h 3 Aug 2005 14:07:24 -0000 1.66 +++ ext/mbstring/mbstring.h 24 Dec 2005 13:01:47 -0000 @@ -180,6 +180,7 @@ int current_filter_illegal_substchar; long func_overload; zend_bool encoding_translation; + long strict_detection; mbfl_buffer_converter *outconv; #if HAVE_MBREGEX && defined(PHP_MBREGEX_GLOBALS) PHP_MBREGEX_GLOBALS Index: ext/mbstring/libmbfl/mbfl/mbfilter.c =================================================================== RCS file: /repository/php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c,v retrieving revision 1.7.2.2 diff -u -r1.7.2.2 mbfilter.c --- ext/mbstring/libmbfl/mbfl/mbfilter.c 24 Dec 2005 04:32:42 -0000 1.7.2.2 +++ ext/mbstring/libmbfl/mbfl/mbfilter.c 24 Dec 2005 13:01:47 -0000 @@ -336,7 +336,7 @@ * encoding detector */ mbfl_encoding_detector * -mbfl_encoding_detector_new(enum mbfl_no_encoding *elist, int elistsz) +mbfl_encoding_detector_new(enum mbfl_no_encoding *elist, int elistsz, int strict) { mbfl_encoding_detector *identd; @@ -371,6 +371,9 @@ } identd->filter_list_size = num; + /* set strict flag */ + identd->strict = strict; + return identd; } @@ -441,10 +444,24 @@ while (n >= 0) { filter = identd->filter_list[n]; if (!filter->flag) { + if (identd->strict && filter->status) { + continue; + } encoding = filter->encoding->no_encoding; } n--; } + + if (encoding == mbfl_no_encoding_invalid) { + n = identd->filter_list_size - 1; + while (n >= 0) { + filter = identd->filter_list[n]; + if (!filter->flag) { + encoding = filter->encoding->no_encoding; + } + n--; + } + } } return encoding; @@ -622,11 +639,11 @@ } enum mbfl_no_encoding -mbfl_identify_encoding_no(mbfl_string *string, enum mbfl_no_encoding *elist, int elistsz) +mbfl_identify_encoding_no(mbfl_string *string, enum mbfl_no_encoding *elist, int elistsz, int strict) { const mbfl_encoding *encoding; - encoding = mbfl_identify_encoding(string, elist, elistsz, 0); + encoding = mbfl_identify_encoding(string, elist, elistsz, strict); if (encoding != NULL && encoding->no_encoding > mbfl_no_encoding_charset_min && encoding->no_encoding < mbfl_no_encoding_charset_max) { Index: ext/mbstring/libmbfl/mbfl/mbfilter.h =================================================================== RCS file: /repository/php-src/ext/mbstring/libmbfl/mbfl/mbfilter.h,v retrieving revision 1.4 diff -u -r1.4 mbfilter.h --- ext/mbstring/libmbfl/mbfl/mbfilter.h 23 Feb 2005 13:35:34 -0000 1.4 +++ ext/mbstring/libmbfl/mbfl/mbfilter.h 24 Dec 2005 13:01:47 -0000 @@ -138,9 +138,10 @@ struct _mbfl_encoding_detector { mbfl_identify_filter **filter_list; int filter_list_size; + int strict; }; -MBFLAPI extern mbfl_encoding_detector * mbfl_encoding_detector_new(enum mbfl_no_encoding *elist, int elistsz); +MBFLAPI extern mbfl_encoding_detector * mbfl_encoding_detector_new(enum mbfl_no_encoding *elist, int elistsz, int strict); MBFLAPI extern void mbfl_encoding_detector_delete(mbfl_encoding_detector *identd); MBFLAPI extern int mbfl_encoding_detector_feed(mbfl_encoding_detector *identd, mbfl_string *string); MBFLAPI extern enum mbfl_no_encoding mbfl_encoding_detector_judge(mbfl_encoding_detector *identd); @@ -163,7 +164,7 @@ mbfl_identify_encoding_name(mbfl_string *string, enum mbfl_no_encoding *elist, int elistsz, int strict); MBFLAPI extern enum mbfl_no_encoding -mbfl_identify_encoding_no(mbfl_string *string, enum mbfl_no_encoding *elist, int elistsz); +mbfl_identify_encoding_no(mbfl_string *string, enum mbfl_no_encoding *elist, int elistsz, int strict); /* * strlen