hirokawa                Sun Dec 25 15:21:54 2005 EDT

  Modified files:              
    /php-src/ext/mbstring       mb_gpc.c mbstring.c mbstring.h 
    /php-src/ext/mbstring/libmbfl/mbfl  mbfilter.c mbfilter.h 
  Log:
  fixed #35711, added mbstring.strict_detection to detect the encoding striktly.
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/mbstring/mb_gpc.c?r1=1.17&r2=1.18&diff_format=u
Index: php-src/ext/mbstring/mb_gpc.c
diff -u php-src/ext/mbstring/mb_gpc.c:1.17 php-src/ext/mbstring/mb_gpc.c:1.18
--- php-src/ext/mbstring/mb_gpc.c:1.17  Wed Aug  3 14:07:24 2005
+++ php-src/ext/mbstring/mb_gpc.c       Sun Dec 25 15:21:54 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: mb_gpc.c,v 1.17 2005/08/03 14:07:24 sniper Exp $ */
+/* $Id: mb_gpc.c,v 1.18 2005/12/25 15:21:54 hirokawa Exp $ */
 
 /* {{{ includes */
 #ifdef HAVE_CONFIG_H
@@ -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) {
http://cvs.php.net/viewcvs.cgi/php-src/ext/mbstring/mbstring.c?r1=1.232&r2=1.233&diff_format=u
Index: php-src/ext/mbstring/mbstring.c
diff -u php-src/ext/mbstring/mbstring.c:1.232 
php-src/ext/mbstring/mbstring.c:1.233
--- php-src/ext/mbstring/mbstring.c:1.232       Fri Dec 23 11:14:54 2005
+++ php-src/ext/mbstring/mbstring.c     Sun Dec 25 15:21:54 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: mbstring.c,v 1.232 2005/12/23 11:14:54 hirokawa Exp $ */
+/* $Id: mbstring.c,v 1.233 2005/12/25 15:21:54 hirokawa Exp $ */
 
 /*
  * PHP 4 Multibyte String module "mbstring"
@@ -733,6 +733,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()
 /* }}} */
 
@@ -768,6 +771,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);
@@ -2021,7 +2025,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 {
@@ -2213,7 +2217,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) {
@@ -2263,6 +2267,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;
@@ -2554,7 +2561,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) {
@@ -3173,7 +3180,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) {
@@ -3193,7 +3200,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;
@@ -3570,7 +3577,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;
http://cvs.php.net/viewcvs.cgi/php-src/ext/mbstring/mbstring.h?r1=1.66&r2=1.67&diff_format=u
Index: php-src/ext/mbstring/mbstring.h
diff -u php-src/ext/mbstring/mbstring.h:1.66 
php-src/ext/mbstring/mbstring.h:1.67
--- php-src/ext/mbstring/mbstring.h:1.66        Wed Aug  3 14:07:24 2005
+++ php-src/ext/mbstring/mbstring.h     Sun Dec 25 15:21:54 2005
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: mbstring.h,v 1.66 2005/08/03 14:07:24 sniper Exp $ */
+/* $Id: mbstring.h,v 1.67 2005/12/25 15:21:54 hirokawa Exp $ */
 
 /*
  * PHP 4 Multibyte String module "mbstring" (currently only for Japanese)
@@ -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     
http://cvs.php.net/viewcvs.cgi/php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c?r1=1.9&r2=1.10&diff_format=u
Index: php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c
diff -u php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c:1.9 
php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c:1.10
--- php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c:1.9    Sat Dec 24 01:20:26 2005
+++ php-src/ext/mbstring/libmbfl/mbfl/mbfilter.c        Sun Dec 25 15:21:54 2005
@@ -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,25 @@
                while (n >= 0) {
                        filter = identd->filter_list[n];
                        if (!filter->flag) {
+                               if (identd->strict && filter->status) {
+                                       continue;
+                               }
                                encoding = filter->encoding->no_encoding;
                        }
                        n--;
                }
+
+               /* fallback judge */
+               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;
@@ -623,11 +641,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) {
http://cvs.php.net/viewcvs.cgi/php-src/ext/mbstring/libmbfl/mbfl/mbfilter.h?r1=1.4&r2=1.5&diff_format=u
Index: php-src/ext/mbstring/libmbfl/mbfl/mbfilter.h
diff -u php-src/ext/mbstring/libmbfl/mbfl/mbfilter.h:1.4 
php-src/ext/mbstring/libmbfl/mbfl/mbfilter.h:1.5
--- php-src/ext/mbstring/libmbfl/mbfl/mbfilter.h:1.4    Wed Feb 23 13:35:34 2005
+++ php-src/ext/mbstring/libmbfl/mbfl/mbfilter.h        Sun Dec 25 15:21:54 2005
@@ -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

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to