mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-01 19:27:39 +08:00
Fixed bug that Str::replaceLast
with empty search cannot work as expected. (#6217)
This commit is contained in:
parent
24b4ed652f
commit
5cb46cb801
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user