diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 2ffea75d16b8..66028c8beecc 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -489,7 +489,7 @@ public static function matchAll($pattern, $subject) */ public static function padBoth($value, $length, $pad = ' ') { - return str_pad($value, $length, $pad, STR_PAD_BOTH); + return str_pad($value, strlen($value) - mb_strlen($value) + $length, $pad, STR_PAD_BOTH); } /** @@ -502,7 +502,7 @@ public static function padBoth($value, $length, $pad = ' ') */ public static function padLeft($value, $length, $pad = ' ') { - return str_pad($value, $length, $pad, STR_PAD_LEFT); + return str_pad($value, strlen($value) - mb_strlen($value) + $length, $pad, STR_PAD_LEFT); } /** @@ -515,7 +515,7 @@ public static function padLeft($value, $length, $pad = ' ') */ public static function padRight($value, $length, $pad = ' ') { - return str_pad($value, $length, $pad, STR_PAD_RIGHT); + return str_pad($value, strlen($value) - mb_strlen($value) + $length, $pad, STR_PAD_RIGHT); } /** diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index 1886bc69fd5b..0daa6248c939 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -609,18 +609,21 @@ public function testPadBoth() { $this->assertSame('__Alien___', Str::padBoth('Alien', 10, '_')); $this->assertSame(' Alien ', Str::padBoth('Alien', 10)); + $this->assertSame(' ❤MultiByte☆ ', Str::padBoth('❤MultiByte☆', 16)); } public function testPadLeft() { $this->assertSame('-=-=-Alien', Str::padLeft('Alien', 10, '-=')); $this->assertSame(' Alien', Str::padLeft('Alien', 10)); + $this->assertSame(' ❤MultiByte☆', Str::padLeft('❤MultiByte☆', 16)); } public function testPadRight() { $this->assertSame('Alien-----', Str::padRight('Alien', 10, '-')); $this->assertSame('Alien ', Str::padRight('Alien', 10)); + $this->assertSame('❤MultiByte☆ ', Str::padRight('❤MultiByte☆', 16)); } public function testSwapKeywords(): void diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index c73db92398ee..4c813c3d57a5 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -828,18 +828,21 @@ public function testPadBoth() { $this->assertSame('__Alien___', (string) $this->stringable('Alien')->padBoth(10, '_')); $this->assertSame(' Alien ', (string) $this->stringable('Alien')->padBoth(10)); + $this->assertSame(' ❤MultiByte☆ ', (string) $this->stringable('❤MultiByte☆')->padBoth(16)); } public function testPadLeft() { $this->assertSame('-=-=-Alien', (string) $this->stringable('Alien')->padLeft(10, '-=')); $this->assertSame(' Alien', (string) $this->stringable('Alien')->padLeft(10)); + $this->assertSame(' ❤MultiByte☆', (string) $this->stringable('❤MultiByte☆')->padLeft(16)); } public function testPadRight() { $this->assertSame('Alien-----', (string) $this->stringable('Alien')->padRight(10, '-')); $this->assertSame('Alien ', (string) $this->stringable('Alien')->padRight(10)); + $this->assertSame('❤MultiByte☆ ', (string) $this->stringable('❤MultiByte☆')->padRight(16)); } public function testChunk()