Fixed bug that Str::replaceLast with empty search cannot work as expected. (#6217)

This commit is contained in:
Hestia Allen 2023-10-16 02:53:07 -05:00 committed by GitHub
parent 24b4ed652f
commit 5cb46cb801
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View File

@ -1,5 +1,9 @@
# v3.0.40 - TBD
## Fixed
- [#6217](https://github.com/hyperf/hyperf/pull/6217) Fixed bug that `Str::replaceLast` with empty search cannot work as expected.
## Optimized
- [#6209](https://github.com/hyperf/hyperf/pull/6209) Support for phpredis 6.x [sentinel](https://github.com/phpredis/phpredis/blob/develop/sentinel.md#examples-for-version-60-or-later)

View File

@ -601,6 +601,10 @@ class Str
*/
public static function replaceLast(string $search, string $replace, string $subject): string
{
if ($search == '') {
return $subject;
}
$position = strrpos($subject, $search);
if ($position !== false) {

View File

@ -558,4 +558,10 @@ class StrTest extends TestCase
$this->assertSame($item[0], Str::convertCase(...$item[1]));
}
}
public function testReplaceLast()
{
$this->assertSame('Hello earth', Str::replaceLast('world', 'earth', 'Hello world'));
$this->assertSame('Hello world', Str::replaceLast('', 'earth', 'Hello world'));
}
}