summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2005-04-03 18:08:40 (GMT)
committerIlia Alshanetsky <iliaa@php.net>2005-04-03 18:08:40 (GMT)
commitca10457a581ea760bfb8307489013f44bf8118ff (patch)
treef4e1d0723fbbee912c1d4d588a9e0b5820df6c06 /ext
parent1d25fc5c7b62f763b66a4c745d5e29894419aca9 (diff)
downloadphp-ca10457a581ea760bfb8307489013f44bf8118ff.tar.gz
Fixed bug #32530 (chunk_split() does not append endstr if chunklen is
longer then the original string).
Diffstat (limited to 'ext')
-rw-r--r--ext/standard/string.c8
-rw-r--r--ext/standard/tests/strings/chunk_split.phpt3
2 files changed, 10 insertions, 1 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 88b5b55..36c3c22 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 6aec9fd..b6bed3a 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