Skip to content

Commit 0ef002c

Browse files
committed
Fix php8.2 deprecation: mb_strwidth():
- Passing null to parameter laravel#1 ($string) of type string is deprecated - add test
1 parent e1afe68 commit 0ef002c

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/Illuminate/Support/Str.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,10 @@ public static function length($value, $encoding = null)
721721
*/
722722
public static function limit($value, $limit = 100, $end = '...', $preserveWords = false)
723723
{
724+
if ($value === null) {
725+
return $value;
726+
}
727+
724728
if (mb_strwidth($value, 'UTF-8') <= $limit) {
725729
return $value;
726730
}

tests/Support/SupportStrTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,8 @@ public function testLimit()
766766
$this->assertSame('这是一...', Str::limit($nonAsciiString, 6, preserveWords: true));
767767
$this->assertSame('这是一', Str::limit($nonAsciiString, 6, ''));
768768
$this->assertSame('这是一', Str::limit($nonAsciiString, 6, '', true));
769+
770+
$this->assertSame(null, Str::limit(null));
769771
}
770772

771773
public function testLength()

0 commit comments

Comments
 (0)