Skip to content

Commit c44f65b

Browse files
committed
[String] fix beforeLast/afterLast
1 parent ae819fc commit c44f65b

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

AbstractString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function afterLast($needle, bool $includeNeedle = false, int $offset = 0)
139139
$n = (string) $n;
140140
$j = $this->indexOfLast($n, $offset);
141141

142-
if (null !== $j && $j > $i) {
142+
if (null !== $j && $j >= $i) {
143143
$i = $offset = $j;
144144
$str->string = $n;
145145
}
@@ -208,7 +208,7 @@ public function beforeLast($needle, bool $includeNeedle = false, int $offset = 0
208208
$n = (string) $n;
209209
$j = $this->indexOfLast($n, $offset);
210210

211-
if (null !== $j && $j > $i) {
211+
if (null !== $j && $j >= $i) {
212212
$i = $offset = $j;
213213
$str->string = $n;
214214
}

Tests/AbstractAsciiTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ public static function provideBeforeAfterLast()
711711
['orld', 'o', 'hello world', 0, false],
712712
['abacab', 'ab', 'abacabab', 1, true],
713713
['ab', 'ab', 'abacabab', 1, false],
714+
['hello world', 'hello', 'hello world', 0, false],
714715
];
715716
}
716717

0 commit comments

Comments
 (0)