]> granicus.if.org Git - php/commitdiff
- Fixed bug #49354 (mb_strcut() cuts wrong length when offset is within a
authorMoriyoshi Koizumi <moriyoshi@php.net>
Wed, 23 Sep 2009 15:22:47 +0000 (15:22 +0000)
committerMoriyoshi Koizumi <moriyoshi@php.net>
Wed, 23 Sep 2009 15:22:47 +0000 (15:22 +0000)
  multibyte character).

(This bug was introduced by the commit by r202895. Please double-check the
 specification of the function you are going to *fix*.)

NEWS
ext/mbstring/mbstring.c
ext/mbstring/tests/bug49354.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 7f1a7b3515482f1904db234d4ed7d4d68693e73d..dfa65b7afbe24ff19c96efbbb72462f96c09d0b7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ PHP                                                                        NEWS
   mbstring.strict_mode is turned on). (Moriyoshi)
 - Fixed bug #49531 (CURLOPT_INFILESIZE sometimes causes warning "CURLPROTO_FILE
   cannot be set"). (Felipe)
+- Fixed bug #49354 (mb_strcut() cuts wrong length when offset is in the middle
+  of a multibyte character). (Moriyoshi)
 - Fixed bug #49528 (UTF-16 strings prefixed by BOMs wrondly converted).
   (Moriyoshi)
 
index 6dae29cee633b4b2d627529a504dcee4af17e340..02badf9ff622b75914c5b68327c1e7b185e43362 100644 (file)
@@ -2272,9 +2272,6 @@ PHP_FUNCTION(mb_strcut)
        if (from > Z_STRLEN_PP(arg1)) {
                RETURN_FALSE;
        }
-       if (((unsigned) from + (unsigned) len) > Z_STRLEN_PP(arg1)) {
-               len = Z_STRLEN_PP(arg1) - from;
-       }
 
        ret = mbfl_strcut(&string, &result, from, len);
        if (ret != NULL) {
diff --git a/ext/mbstring/tests/bug49354.phpt b/ext/mbstring/tests/bug49354.phpt
new file mode 100644 (file)
index 0000000..c25b405
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Bug #49354 (mb_strcut() cuts wrong length when offset is in the middle of a multibyte character)
+--SKIPIF--
+<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
+--FILE--
+<?php
+$crap = 'AåBäCöDü';
+var_dump(mb_strcut($crap, 0, 100, 'UTF-8'));
+var_dump(mb_strcut($crap, 1, 100, 'UTF-8'));
+var_dump(mb_strcut($crap, 2, 100, 'UTF-8'));
+var_dump(mb_strcut($crap, 3, 100, 'UTF-8'));
+var_dump(mb_strcut($crap, 12, 100, 'UTF-8'));
+var_dump(mb_strcut($crap, 13, 100, 'UTF-8'));
+?>
+--EXPECT--
+string(12) "AåBäCöDü"
+string(11) "åBäCöDü"
+string(11) "åBäCöDü"
+string(9) "BäCöDü"
+string(0) ""
+bool(false)