summaryrefslogtreecommitdiff
path: root/ext/mbstring
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
commit0c974164e248c602988bc9d6725beb1a81658b50 (patch)
treea5d7ae026237d88a0bbd9fdbde3036cd7f887b46 /ext/mbstring
parent4b1c7c56154613c0fcb7c01ee673eb8595d027c2 (diff)
downloadphp-git-0c974164e248c602988bc9d6725beb1a81658b50.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*.)
Diffstat (limited to 'ext/mbstring')
-rw-r--r--ext/mbstring/mbstring.c4
-rw-r--r--ext/mbstring/tests/bug49354.phpt21
2 files changed, 21 insertions, 4 deletions
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 4182425170..92f2db61b3 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -2665,10 +2665,6 @@ PHP_FUNCTION(mb_strcut)
RETURN_FALSE;
}
- if (((unsigned int)from + (unsigned int)len) > string.len) {
- len = string.len - from;
- }
-
ret = mbfl_strcut(&string, &result, from, len);
if (ret == NULL) {
RETURN_FALSE;
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)