]> granicus.if.org Git - php/commitdiff
Fix #75944: Wrong cp1251 detection
authorChristoph M. Becker <cmbecker69@gmx.de>
Mon, 19 Mar 2018 12:51:40 +0000 (13:51 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Mon, 19 Mar 2018 13:24:27 +0000 (14:24 +0100)
`\xFF` is a valid character of CP-1251.

NEWS
ext/mbstring/libmbfl/filters/mbfilter_cp1251.c
ext/mbstring/tests/bug75944.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 5a1d3b2f4bb469d6b4779e65f2c45cb9d165b210..921d9123d1ca113c2e6981a880a56120219e6971 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? ????, PHP 7.1.17
 
+- Mbstring:
+  . Fixed bug #75944 (Wrong cp1251 detection). (dmk001)
 
 
 29 Mar 2018, PHP 7.1.16
index a26ce19492d5226d36cea3a43ad221e64fa8a1ba..2d47ac304aee460c55465f07ef26f871be4575e9 100644 (file)
@@ -142,7 +142,7 @@ mbfl_filt_conv_wchar_cp1251(int c, mbfl_convert_filter *filter)
 /* all of this is so ugly now! */
 static int mbfl_filt_ident_cp1251(int c, mbfl_identify_filter *filter)
 {
-       if (c >= 0x80 && c < 0xff)
+       if (c >= 0x80 && c <= 0xff)
                filter->flag = 0;
        else
                filter->flag = 1; /* not it */
diff --git a/ext/mbstring/tests/bug75944.phpt b/ext/mbstring/tests/bug75944.phpt
new file mode 100644 (file)
index 0000000..81788d7
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--\r
+Bug #75944 (wrong detection cp1251 encoding because of missing last cyrillic letter)\r
+--SKIPIF--\r
+<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>\r
+--FILE--\r
+<?php\r
+var_dump(mb_detect_encoding(chr(0xfe), array('CP-1251'))); // letter '?'\r
+var_dump(mb_detect_encoding(chr(0xff), array('CP-1251'))); // letter '?'\r
+?>\r
+--EXPECT--\r
+string(12) "Windows-1251"\r
+string(12) "Windows-1251"\r
+\r