moriyoshi                                Fri, 11 Sep 2009 21:26:18 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=288273

Log:
- Fix bug #49536 (mb_detect_encoding() returns incorrect results when 
strict_mode is turned on.)
  (patch by komura, thanks!)

Bug: http://bugs.php.net/49536 (Open) mb_detect_encoding() returns incorrect 
results when strict_mode is turned on
      
Changed paths:
    U   
php/php-src/branches/PHP_5_3/ext/mbstring/libmbfl/filters/mbfilter_utf8.c
    U   php/php-src/branches/PHP_5_3/ext/mbstring/libmbfl/mbfl/mbfilter.c
    A   php/php-src/branches/PHP_5_3/ext/mbstring/tests/bug49536.phpt
    U   php/php-src/trunk/ext/mbstring/libmbfl/filters/mbfilter_utf8.c
    U   php/php-src/trunk/ext/mbstring/libmbfl/mbfl/mbfilter.c
    A   php/php-src/trunk/ext/mbstring/tests/bug49536.phpt

Modified: 
php/php-src/branches/PHP_5_3/ext/mbstring/libmbfl/filters/mbfilter_utf8.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mbstring/libmbfl/filters/mbfilter_utf8.c   
2009-09-11 16:43:49 UTC (rev 288272)
+++ php/php-src/branches/PHP_5_3/ext/mbstring/libmbfl/filters/mbfilter_utf8.c   
2009-09-11 21:26:18 UTC (rev 288273)
@@ -220,7 +220,7 @@
        if (c < 0x80) {
                if (c < 0) {
                        filter->flag = 1;       /* bad */
-               } else if (c != 0 && filter->status) {
+               } else if (filter->status) {
                        filter->flag = 1;       /* bad */
                }
                filter->status = 0;

Modified: php/php-src/branches/PHP_5_3/ext/mbstring/libmbfl/mbfl/mbfilter.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mbstring/libmbfl/mbfl/mbfilter.c   
2009-09-11 16:43:49 UTC (rev 288272)
+++ php/php-src/branches/PHP_5_3/ext/mbstring/libmbfl/mbfl/mbfilter.c   
2009-09-11 21:26:18 UTC (rev 288273)
@@ -622,7 +622,7 @@
        if (!encoding) {
                for (i = 0; i < num; i++) {
                        filter = &flist[i];
-                       if (!filter->flag) {
+                       if (!filter->flag && (!strict || !filter->status)) {
                                encoding = filter->encoding;
                                break;
                        }

Added: php/php-src/branches/PHP_5_3/ext/mbstring/tests/bug49536.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mbstring/tests/bug49536.phpt               
                (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/mbstring/tests/bug49536.phpt       
2009-09-11 21:26:18 UTC (rev 288273)
@@ -0,0 +1,20 @@
+--TEST--
+Bug #49536 (mb_detect_encoding() returns incorrect results when strict_mode is 
turned on)
+--SKIPIF--
+<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
+--FILE--
+<?php
+// non-strict mode
+var_dump(mb_detect_encoding("A\x81", "SJIS", false));
+// strict mode
+var_dump(mb_detect_encoding("A\x81", "SJIS", true));
+// non-strict mode
+var_dump(mb_detect_encoding("\xc0\x00", "UTF-8", false));
+// strict mode
+var_dump(mb_detect_encoding("\xc0\x00", "UTF-8", true));
+?>
+--EXPECT--
+string(4) "SJIS"
+bool(false)
+string(5) "UTF-8"
+bool(false)

Modified: php/php-src/trunk/ext/mbstring/libmbfl/filters/mbfilter_utf8.c
===================================================================
--- php/php-src/trunk/ext/mbstring/libmbfl/filters/mbfilter_utf8.c      
2009-09-11 16:43:49 UTC (rev 288272)
+++ php/php-src/trunk/ext/mbstring/libmbfl/filters/mbfilter_utf8.c      
2009-09-11 21:26:18 UTC (rev 288273)
@@ -220,7 +220,7 @@
        if (c < 0x80) {
                if (c < 0) {
                        filter->flag = 1;       /* bad */
-               } else if (c != 0 && filter->status) {
+               } else if (filter->status) {
                        filter->flag = 1;       /* bad */
                }
                filter->status = 0;

Modified: php/php-src/trunk/ext/mbstring/libmbfl/mbfl/mbfilter.c
===================================================================
--- php/php-src/trunk/ext/mbstring/libmbfl/mbfl/mbfilter.c      2009-09-11 
16:43:49 UTC (rev 288272)
+++ php/php-src/trunk/ext/mbstring/libmbfl/mbfl/mbfilter.c      2009-09-11 
21:26:18 UTC (rev 288273)
@@ -622,7 +622,7 @@
        if (!encoding) {
                for (i = 0; i < num; i++) {
                        filter = &flist[i];
-                       if (!filter->flag) {
+                       if (!filter->flag && (!strict || !filter->status)) {
                                encoding = filter->encoding;
                                break;
                        }

Added: php/php-src/trunk/ext/mbstring/tests/bug49536.phpt
===================================================================
--- php/php-src/trunk/ext/mbstring/tests/bug49536.phpt                          
(rev 0)
+++ php/php-src/trunk/ext/mbstring/tests/bug49536.phpt  2009-09-11 21:26:18 UTC 
(rev 288273)
@@ -0,0 +1,20 @@
+--TEST--
+Bug #49536 (mb_detect_encoding() returns incorrect results when strict_mode is 
turned on)
+--SKIPIF--
+<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
+--FILE--
+<?php
+// non-strict mode
+var_dump(mb_detect_encoding("A\x81", "SJIS", false));
+// strict mode
+var_dump(mb_detect_encoding("A\x81", "SJIS", true));
+// non-strict mode
+var_dump(mb_detect_encoding("\xc0\x00", "UTF-8", false));
+// strict mode
+var_dump(mb_detect_encoding("\xc0\x00", "UTF-8", true));
+?>
+--EXPECT--
+string(4) "SJIS"
+bool(false)
+string(5) "UTF-8"
+bool(false)

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

Reply via email to