summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoriyoshi Koizumi <moriyoshi@php.net>2009-09-23 15:22:47 +0000
committerMoriyoshi Koizumi <moriyoshi@php.net>2009-09-23 15:22:47 +0000
commitc2471b4950091c71da5e3f686d6d455e8e3092ea (patch)
tree00e2d1f851ab6f2a11153a7ac5829ed1a3ba3b4a
parent4a391f68d59ab4238e33627e57000197840cd791 (diff)
downloadphp-git-c2471b4950091c71da5e3f686d6d455e8e3092ea.tar.gz
- Fixed bug #49354 (mb_strcut() cuts wrong length when offset is within a
multibyte character). (This bug was introduced by the commit by r202895. Please double-check the specification of the function you are going to *fix*.)
-rw-r--r--NEWS2
-rw-r--r--ext/mbstring/mbstring.c3
-rw-r--r--ext/mbstring/tests/bug49354.phpt21
3 files changed, 23 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 7f1a7b3515..dfa65b7afb 100644
--- 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)
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 6dae29cee6..02badf9ff6 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -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
index 0000000000..c25b405d82
--- /dev/null
+++ b/ext/mbstring/tests/bug49354.phpt
@@ -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)