[php-src] PHP-8.6: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Mon, 05 Oct 2026 17:46:38 +0000
Subject: [php-src] PHP-8.6: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141972@lists.php.net to get a copy of this message
Author: Arnaud Le Blanc (arnaud-lb) Date: 2026-10-05T19:45:33+02:00 Commit: https://github.com/php/php-src/commit/a0ed6cc298db161fa66317d2a5e1cbeddd2090ca Raw diff: https://github.com/php/php-src/commit/a0ed6cc298db161fa66317d2a5e1cbeddd2090ca.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: Fix wordwrap() ignoring an existing break at the end of the string (#24116) Changed paths: A ext/standard/tests/strings/wordwrap_trailing_break.phpt M NEWS M ext/standard/string.c Diff: diff --git a/NEWS b/NEWS index 94cad245e0f1..ffaeab9dc752 100644 --- a/NEWS +++ b/NEWS @@ -212,6 +212,8 @@ PHP NEWS PROCESS_INFORMATION, an indeterminate comspec pointer after a failed lookup, and an unchecked CreateFileA() failure. (Ilia Alshanetsky) . Fix persistent stream context lifetime during shutdown (Levi Morrison) + . Fix wordwrap() ignoring an existing break at the end of the string + (Nicolas Grekas) - Tidy: . Fixed a use-after-free when a tidyNode is used after its document is diff --git a/ext/standard/string.c b/ext/standard/string.c index 5e7b7d7c8921..824cb1e8a079 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -767,7 +767,7 @@ PHP_FUNCTION(wordwrap) /* when we hit an existing break, copy to new buffer, and * fix up laststart and lastspace */ if (ZSTR_VAL(text)[current] == breakchar[0] - && current + breakchar_len < ZSTR_LEN(text) + && current + breakchar_len <= ZSTR_LEN(text) && !strncmp(ZSTR_VAL(text) + current, breakchar, breakchar_len)) { memcpy(ZSTR_VAL(newtext) + newtextlen, ZSTR_VAL(text) + laststart, current - laststart + breakchar_len); newtextlen += current - laststart + breakchar_len; diff --git a/ext/standard/tests/strings/wordwrap_trailing_break.phpt b/ext/standard/tests/strings/wordwrap_trailing_break.phpt new file mode 100644 index 000000000000..2e57ce176665 --- /dev/null +++ b/ext/standard/tests/strings/wordwrap_trailing_break.phpt @@ -0,0 +1,28 @@ +--TEST-- +wordwrap() recognizes an existing break at the end of the string +--FILE-- +<?php +$tests = [ + ["abc\n", 3, "\n", true], + ["ab cd\n", 5, "\n", true], + ["abcd\n", 3, "\n", true], + ["abc\nabc\n", 3, "\n", true], + ["abc-", 3, "-", true], + ["abc\r\n", 3, "\r\n", true], + ["\r\n", 1, "\r\n", true], + ["ab cd\r\n", 5, "\r\n", false], +]; + +foreach ($tests as [$text, $width, $break, $cut]) { + echo json_encode(wordwrap($text, $width, $break, $cut)), "\n"; +} +?> +--EXPECT-- +"abc\n" +"ab cd\n" +"abc\nd\n" +"abc\nabc\n" +"abc-" +"abc\r\n" +"\r\n" +"ab cd\r\n"

« previous php.cvs (#141972) next »