Skip to content

Commit 18f97f1

Browse files
Merge branch 'develop' into fix-sync-request-after-get-change
2 parents 59ff334 + 99c3f24 commit 18f97f1

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎system/Helpers/text_helper.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ function word_wrap(string $str, int $charlim = 76): string
383383

384384
$temp = '';
385385

386-
while (mb_strlen($line) > $charlim) {
386+
// A limit of 1 can't be used to split a word (each piece needs room for
387+
// the continuation), so the word is kept whole, like a long URL.
388+
while ($charlim > 1 && mb_strlen($line) > $charlim) {
387389
// If the over-length word is a URL we won't wrap it
388390
if (preg_match('!\[url.+\]|://|www\.!', $line)) {
389391
break;

‎tests/system/Helpers/TextHelperTest.php‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,27 @@ public function testEllipsize(): void
358358
}
359359
}
360360

361+
/**
362+
* A character limit below 2 used to make word_wrap() loop forever.
363+
*/
364+
#[DataProvider('provideWordWrapSmallCharLimit')]
365+
public function testWordWrapSmallCharLimit(int $charlim): void
366+
{
367+
$this->assertSame("aaaa\nbbbb", word_wrap('aaaa bbbb', $charlim));
368+
}
369+
370+
/**
371+
* @return iterable<string, array{int}>
372+
*/
373+
public static function provideWordWrapSmallCharLimit(): iterable
374+
{
375+
yield 'one' => [1];
376+
377+
yield 'zero' => [0];
378+
379+
yield 'negative' => [-5];
380+
}
381+
361382
public function testWordWrap(): void
362383
{
363384
$string = 'Here is a simple string of text that will help us demonstrate this function.';

‎user_guide_src/source/changelogs/v4.7.5.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Bugs Fixed
5757
- **Debug:** Fixed a bug where ``Timer::start()`` treated ``0.0`` as an empty value and substituted the current time.
5858
- **Files:** Fixed a bug where ``File::move()`` and ``UploadedFile::move()`` set executable and overly permissive file permissions (``0777 & ~umask()`` instead of ``0666 & ~umask()``), and ``UploadedFile::move()`` targeted the parent directory instead of the destination file for ``chmod()``.
5959
- **Helpers:** Fixed a bug where ``get_dir_file_info()`` returned incomplete entries for subdirectories and missing files instead of omitting them.
60+
- **Helpers:** Fixed a bug where ``word_wrap()`` entered an infinite loop when the character limit was below 2. Over-length words are now kept whole in that case.
6061
- **Honeypot:** Fixed a bug where bot detection returned an HTTP 500 response instead of 403 (Forbidden).
6162
- **HTTP:** Fixed a bug where ``IncomingRequest::getVar()`` returned stale data after ``$_GET`` was updated during URI parsing. It now returns a merged view of ``$_GET``, ``$_POST``, and ``$_COOKIE`` (respecting the ``request_order`` ini setting) instead of reading the stale ``$_REQUEST``.
6263
- **I18n:** Fixed a bug where ``Time::today()``, ``Time::yesterday()``, and ``Time::tomorrow()`` ignored the specified ``$timezone`` and ``setTestNow()`` when calculating the day.

0 commit comments

Comments
 (0)