]> granicus.if.org Git - php/commitdiff
- Fix bug #49536 (mb_detect_encoding() returns incorrect results when strict_mode...
authorMoriyoshi Koizumi <moriyoshi@php.net>
Fri, 11 Sep 2009 21:26:18 +0000 (21:26 +0000)
committerMoriyoshi Koizumi <moriyoshi@php.net>
Fri, 11 Sep 2009 21:26:18 +0000 (21:26 +0000)
  (patch by komura, thanks!)

ext/mbstring/libmbfl/filters/mbfilter_utf8.c
ext/mbstring/libmbfl/mbfl/mbfilter.c
ext/mbstring/tests/bug49536.phpt [new file with mode: 0644]

index 20ff983e112687624ad29fc4528ec375828ccfa6..c6777b29fd3f166a3fcc7678f99876b90853c8a8 100644 (file)
@@ -220,7 +220,7 @@ static int mbfl_filt_ident_utf8(int c, mbfl_identify_filter *filter)
        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;
index 1aeb38cc9b7ddcec3d3961a762ec1819e1d26dc0..4997c5a8866dcfa02ce4502ad3a12a789aa8f48e 100644 (file)
@@ -622,7 +622,7 @@ mbfl_identify_encoding(mbfl_string *string, enum mbfl_no_encoding *elist, int el
        if (!encoding) {
                for (i = 0; i < num; i++) {
                        filter = &flist[i];
-                       if (!filter->flag) {
+                       if (!filter->flag && (!strict || !filter->status)) {
                                encoding = filter->encoding;
                                break;
                        }
diff --git a/ext/mbstring/tests/bug49536.phpt b/ext/mbstring/tests/bug49536.phpt
new file mode 100644 (file)
index 0000000..32685d2
--- /dev/null
@@ -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)