]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #32530 (chunk_split() does not append endstr if chunklen is
authorIlia Alshanetsky <iliaa@php.net>
Sun, 3 Apr 2005 18:09:25 +0000 (18:09 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sun, 3 Apr 2005 18:09:25 +0000 (18:09 +0000)
longer then the original string).

NEWS
ext/standard/string.c
ext/standard/tests/strings/chunk_split.phpt

diff --git a/NEWS b/NEWS
index 44e5a54d50a9e7327514b49e4eafb8a2748b45e3..e26b23747779706faa5498f5b66f8e1511a0f188 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,9 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+?? ??? 2005, PHP 5.0.5
+- Fixed bug #32530 (chunk_split() does not append endstr if chunklen is  
+  longer then the original string). (Ilia)
+
 31 Mar 2005, PHP 5.0.4
 - Added SNMPv2 support. (harrie)
 - Added Oracle Instant Client support. (cjbj at hotmail dot com, Tony)
index a9e24338efb588e971e7518d910cefaaed8f9e6e..802b67fa36ec366d0b33e69f6957dbbe5298daae 100644 (file)
@@ -1839,7 +1839,13 @@ PHP_FUNCTION(chunk_split)
        }
 
        if (chunklen > Z_STRLEN_PP(p_str)) {
-               RETURN_STRINGL(Z_STRVAL_PP(p_str), Z_STRLEN_PP(p_str), 1);      
+               /* to maintain BC, we must return original string + ending */
+               result_len = endlen + Z_STRLEN_PP(p_str);
+               result = emalloc(result_len + 1);
+               memcpy(result, Z_STRVAL_PP(p_str), Z_STRLEN_PP(p_str));
+               memcpy(result + Z_STRLEN_PP(p_str), end, endlen);
+               result[result_len] = '\0'; 
+               RETURN_STRINGL(result, result_len, 0);  
        }
 
        if (!Z_STRLEN_PP(p_str)) {
index 6aec9fd24df9ab0842311aa4f06179b49e9a3913..b6bed3ab486d579aed913e3360bbc9c38bbca46f 100644 (file)
@@ -5,6 +5,7 @@ chunk_split() function
 echo chunk_split('abc', 1, '-')."\n";
 echo chunk_split('foooooooooooooooo', 5)."\n";
 echo chunk_split(str_repeat('X', 2*76))."\n";
+echo chunk_split("test", 10, "|end") . "\n";
 ?>
 --EXPECT--
 a-b-c-
@@ -15,3 +16,5 @@ oo
 
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+
+test|end