]> 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:55 +0000 (18:09 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sun, 3 Apr 2005 18:09:55 +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 6d74dccfe13f315c9c36068a32dfe5aa41063fa7..b8612f4cebe70ac23b8c2566cf38bdb297978bbb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ PHP 4                                                                      NEWS
   them sort based on the current locale. (Derick)
 - Fixed bug #32538 (ext/swf/swf.c does not compile with gcc-3.4.x or newer).
   (adam dot greenfield at gmail dot com)
+- Fixed bug #32530 (chunk_split() does not append endstr if chunklen is  
+  longer then the original string). (Ilia)
 
 31 Mar 2005, Version 4.3.11
 - Added Oracle Instant Client support. (cjbj at hotmail dot com, Tony)
index 1f28cf3997381479813e940bcd58c2a994ba5434..51aaff8e0a52cdc1596152c43c23082baa652ad6 100644 (file)
@@ -1576,7 +1576,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 6c0f3fac84d31224cf997afe2b8d0f465352b524..2fa0392f144f969ccf58dce8ead404049983fd92 100644 (file)
@@ -7,6 +7,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-
@@ -17,3 +18,5 @@ oo
 
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+
+test|end