bug #33798 [String] fix beforeLast/afterLast (gharlan)
This PR was merged into the 5.0-dev branch.
Discussion
----------
[String] fix beforeLast/afterLast
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | n/a
| License | MIT
| Doc PR | n/a
```php
echo b('hello world')->beforeLast('hello', true);
// current result: ''
// expected result: 'hello'
echo b('hello world')->afterLast('hello');
// current result: ''
// expected result: ' world'
```
Commits
-------
80b4f81ebf
[String] fix beforeLast/afterLast
This commit is contained in:
commit
564a65732a
@ -139,7 +139,7 @@ abstract class AbstractString implements \JsonSerializable
|
||||
$n = (string) $n;
|
||||
$j = $this->indexOfLast($n, $offset);
|
||||
|
||||
if (null !== $j && $j > $i) {
|
||||
if (null !== $j && $j >= $i) {
|
||||
$i = $offset = $j;
|
||||
$str->string = $n;
|
||||
}
|
||||
@ -208,7 +208,7 @@ abstract class AbstractString implements \JsonSerializable
|
||||
$n = (string) $n;
|
||||
$j = $this->indexOfLast($n, $offset);
|
||||
|
||||
if (null !== $j && $j > $i) {
|
||||
if (null !== $j && $j >= $i) {
|
||||
$i = $offset = $j;
|
||||
$str->string = $n;
|
||||
}
|
||||
|
@ -711,6 +711,7 @@ abstract class AbstractAsciiTestCase extends TestCase
|
||||
['orld', 'o', 'hello world', 0, false],
|
||||
['abacab', 'ab', 'abacabab', 1, true],
|
||||
['ab', 'ab', 'abacabab', 1, false],
|
||||
['hello world', 'hello', 'hello world', 0, false],
|
||||
];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user