From: Ilia Alshanetsky Date: Sun, 3 Apr 2005 18:09:55 +0000 (+0000) Subject: MFH: Fixed bug #32530 (chunk_split() does not append endstr if chunklen is X-Git-Tag: php-4.4.0RC1~161 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fbdc2a9d1005770791d4782ecad2ea0820d1d564;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 6d74dccfe1..b8612f4ceb 100644 --- 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) diff --git a/ext/standard/string.c b/ext/standard/string.c index 1f28cf3997..51aaff8e0a 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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)) { diff --git a/ext/standard/tests/strings/chunk_split.phpt b/ext/standard/tests/strings/chunk_split.phpt index 6c0f3fac84..2fa0392f14 100644 --- a/ext/standard/tests/strings/chunk_split.phpt +++ b/ext/standard/tests/strings/chunk_split.phpt @@ -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