From: Ilia Alshanetsky Date: Sun, 3 Apr 2005 18:09:25 +0000 (+0000) Subject: MFH: Fixed bug #32530 (chunk_split() does not append endstr if chunklen is X-Git-Tag: php-5.0.5RC1~492 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c11305640d5fe2a86c406d7be03e4fbdb2fc095;p=php MFH: Fixed bug #32530 (chunk_split() does not append endstr if chunklen is longer then the original string). --- diff --git a/NEWS b/NEWS index 44e5a54d50..e26b237477 100644 --- 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) diff --git a/ext/standard/string.c b/ext/standard/string.c index a9e24338ef..802b67fa36 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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)) { 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