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

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

index 88b5b551169ed9bc100271cbabc579f5bc0baadb..36c3c223c3581afe8f83df8182c8263e12d725ce 100644 (file)
@@ -1887,7 +1887,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