From: Ilia Alshanetsky Date: Sun, 3 Apr 2005 18:08:40 +0000 (+0000) Subject: Fixed bug #32530 (chunk_split() does not append endstr if chunklen is X-Git-Tag: php-5.0.1b1~625 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ca10457a581ea760bfb8307489013f44bf8118ff;p=php Fixed bug #32530 (chunk_split() does not append endstr if chunklen is longer then the original string). --- diff --git a/ext/standard/string.c b/ext/standard/string.c index 88b5b55116..36c3c223c3 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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)) { diff --git a/ext/standard/tests/strings/chunk_split.phpt b/ext/standard/tests/strings/chunk_split.phpt index 6aec9fd24d..b6bed3ab48 100644 --- a/ext/standard/tests/strings/chunk_split.phpt +++ b/ext/standard/tests/strings/chunk_split.phpt @@ -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