8000 [String] fix before/after[Last]() returning the empty string instead … · symfony/symfony@22a2740 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22a2740

Browse files
[String] fix before/after[Last]() returning the empty string instead of the original one on non-match
1 parent baf8c23 commit 22a2740

File tree

4 files changed

+35
-39
lines changed

4 files changed

+35
-39
lines changed

src/Symfony/Component/String/AbstractString.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public static function wrap(array $values): array
9898
public function after($needle, bool $includeNeedle = false, int $offset = 0): self
9999
{
100100
$str = clone $this;
101-
$str->string = '';
102101
$i = \PHP_INT_MAX;
103102

104103
foreach ((array) $needle as $n) {
@@ -130,7 +129,6 @@ public function after($needle, bool $includeNeedle = false, int $offset = 0): se
130129
public function afterLast($needle, bool $includeNeedle = false, int $offset = 0): self
131130
{
132131
$str = clone $this;
133-
$str->string = '';
134132
$i = null;
135133

136134
foreach ((array) $needle as $n) {
@@ -167,7 +165,6 @@ abstract public function append(string ...$suffix): self;
167165
public function before($needle, bool $includeNeedle = false, int $offset = 0): self
168166
{
169167
$str = clone $this;
170-
$str->string = '';
171168
$i = \PHP_INT_MAX;
172169

173170
foreach ((array) $needle as $n) {
@@ -199,7 +196,6 @@ public function before($needle, bool $includeNeedle = false, int $offset = 0): s
199196
public function beforeLast($needle, bool $includeNeedle = false, int $offset = 0): self
200197
{
201198
$str = clone $this;
202-
$str->string = '';
203199
$i = null;
204200

205201
foreach ((array) $needle as $n) {

src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -766,12 +766,12 @@ public function testBeforeAfter(string $expected, string $needle, string $origin
766766
public static function provideBeforeAfter()
767767
{
768768
return [
769-
['', '', 'hello world', 0, true],
770-
['', '', 'hello world', 0, false],
771-
['', 'w', 'hello World', 0, true],
772-
['', 'w', 'hello World', 0, false],
773-
['', 'o', 'hello world', 10, true],
774-
['', 'o', 'hello world', 10, false],
769+
['hello world', '', 'hello world', 0, true],
770+
['hello world', '', 'hello world', 0, false],
771+
['hello World', 'w', 'hello World', 0, true],
772+
['hello World', 'w', 'hello World', 0, false],
773+
['hello world', 'o', 'hello world', 10, true],
774+
['hello world', 'o', 'hello world', 10, false],
775775
['hello ', 'w', 'hello world', 0, true],
776776
['world', 'w', 'hello world', 0, false],
777777
['hello W', 'O', 'hello WORLD', 0, true],
@@ -794,12 +794,12 @@ public function testBeforeAfterIgnoreCase(string $expected, string $needle, stri
794794
public static function provideBeforeAfterIgnoreCase()
795795
{
796796
return [
797-
['', '', 'hello world', 0, true],
798-
['', '', 'hello world', 0, false],
799-
['', 'foo', 'hello world', 0, true],
800-
['', 'foo', 'hello world', 0, false],
801-
['', 'o', 'hello world', 10, true],
802-
['', 'o', 'hello world', 10, false],
797+
['hello world', '', 'hello world', 0, true],
798+
['hello world', '', 'hello world', 0, false],
799+
['hello world', 'foo', 'hello world', 0, true],
800+
['hello world', 'foo', 'hello world', 0, false],
801+
['hello world', 'o', 'hello world', 10, true],
802+
['hello world', 'o', 'hello world', 10, false],
803803
['hello ', 'w', 'hello world', 0, true],
804804
['world', 'w', 'hello world', 0, false],
805805
['hello ', 'W', 'hello world', 0, true],
@@ -822,12 +822,12 @@ public function testBeforeAfterLast(string $expected, string $needle, string $or
822822
public static function provideBeforeAfterLast()
823823
{
824824
return [
825-
['', '', 'hello world', 0, true],
826-
['', '', 'hello world', 0, false],
827-
['', 'L', 'hello world', 0, true],
828-
['', 'L', 'hello world', 0, false],
829-
['', 'o', 'hello world', 10, true],
830-
['', 'o', 'hello world', 10, false],
825+
['hello world', '', 'hello world', 0, true],
826+
['hello world', '', 'hello world', 0, false],
827+
['hello world', 'L', 'hello world', 0, true],
828+
['hello world', 'L', 'hello world', 0, false],
829+
['hello world', 'o', 'hello world', 10, true],
830+
['hello world', 'o', 'hello world', 10, false],
831831
['hello wor', 'l', 'hello world', 0, true],
832832
['ld', 'l', 'hello world', 0, false],
833833
['hello w', 'o', 'hello world', 0, true],
@@ -851,12 +851,12 @@ public function testBeforeAfterLastIgnoreCase(string $expected, string $needle,
851851
public static function provideBeforeAfterLastIgnoreCase()
852852
{
853853
return [
854-
['', '', 'hello world', 0, true],
855-
['', '', 'hello world', 0, false],
856-
['', 'FOO', 'hello world', 0, true],
857-
['', 'FOO', 'hello world', 0, false],
858-
['', 'o', 'hello world', 10, true],
859-
['', 'o', 'hello world', 10, false],
854+
['hello world', '', 'hello world', 0, true],
855+
['hello world', '', 'hello world', 0, false],
856+
['hello world', 'FOO', 'hello world', 0, true],
857+
['hello world', 'FOO', 'hello world', 0, false],
858+
['hello world', 'o', 'hello world', 10, true],
859+
['hello world', 'o', 'hello world', 10, false],
860860
['hello wor', 'l', 'hello world', 0, true],
861861
['ld', 'l', 'hello world', 0, false],
862862
['hello wor', 'L', 'hello world', 0, true],

src/Symfony/Component/String/Tests/AbstractUnicodeTestCase.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ public static function provideBeforeAfterIgnoreCase(): array
396396
['', '', 'déjàdéjà', 0, true],
397397
['éjàdéjà', 'é', 'déjàdéjà', 0, false],
398398
['d', 'é', 'déjàdéjà', 0, true],
399-
['', 'Ç', 'déjàdéjà', 0, false],
400-
['', 'Ç', 'déjàdéjà', 0, true],
399+
['déjàdéjà', 'Ç', 'déjàdéjà', 0, false],
400+
['déjàdéjà', 'Ç', 'déjàdéjà', 0, true],
401401
]
402402
);
403403
}
@@ -407,8 +407,8 @@ public static function provideBeforeAfterLast(): array
407407
return array_merge(
408408
parent::provideBeforeAfterLast(),
409409
[
410-
['', 'Ç', 'déjàdéjà', 0, false],
411-
['', 'Ç', 'déjàdéjà', 0, true],
410+
['déjàdéjà', 'Ç', 'déjàdéjà', 0, false],
411+
['déjàdéjà', 'Ç', 'déjàdéjà', 0, true],
412412
['éjà', 'é', 'déjàdéjà', 0, false],
413413
['déjàd', 'é', 'déjàdéjà', 0, true],
414414
]
@@ -420,7 +420,7 @@ public static function provideBeforeAfterLastIgnoreCase(): array
420420
return array_merge(
421421
parent::provideBeforeAfterLastIgnoreCase(),
422422
[
423-
['', 'Ç', 'déjàdéjà', 0, false],
423+
['déjàdéjà', 'Ç', 'déjàdéjà', 0, false],
424424
['éjà', 'é', 'déjàdéjà', 0, false],
425425
['éjà', 'É', 'déjàdéjà', 0, false],
426426
]

src/Symfony/Component/String/Tests/UnicodeStringTest.php

Copy file name to clipboard
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ public static function provideBeforeAfterIgnoreCase(): array
186186
return array_merge(
187187
parent::provideBeforeAfterIgnoreCase(),
188188
[
189-
['', 'छेछे', 'दछेच्नुअ', 0, false],
190-
['', 'छेछे', 'दछेच्नुअ', 0, true],
189+
['दछेच्नुअ', 'छेछे', 'दछेच्नुअ', 0, false],
190+
['दछेच्नुअ', 'छेछे', 'दछेच्नुअ', 0, true],
191191
['छेच्नुअ', 'छे', 'दछेच्नुअ', 0, false],
192192
['', 'छे', 'दछेच्नुअ', 0, true],
193193
]
@@ -199,8 +199,8 @@ public static function provideBeforeAfterLast(): array
199199
return array_merge(
200200
parent::provideBeforeAfterLast(),
201201
[
202-
['', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, false],
203-
['', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, true],
202+
['दछेच्नुअ-दछेच्नु-अदछेच्नु', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, false],
203+
['दछेच्नुअ-दछेच्नु-अदछेच्नु', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, true],
204204
['-दछेच्नु', '-द', 'दछेच्नुअ-दछेच्नु-अद-दछेच्नु', 0, false],
205205
['दछेच्नुअ-दछेच्नु-अद', '-द', 'दछेच्नुअ-दछेच्नु-अद-दछेच्नु', 0, true],
206206
]
@@ -212,8 +212,8 @@ public static function provideBeforeAfterLastIgnoreCase(): array
212212
return array_merge(
213213
parent::provideBeforeAfterLastIgnoreCase(),
214214
[
215-
['', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, false],
216-
['', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, true],
215+
['दछेच्नुअ-दछेच्नु-अदछेच्नु', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, false],
216+
['दछेच्नुअ-दछेच्नु-अदछेच्नु', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, true],
217217
['-दछेच्नु', '-द', 'दछेच्नुअ-दछेच्नु-अद-दछेच्नु', 0, false],
218218
['दछेच्नुअ-दछेच्नु-अद', '-द', 'दछेच्नुअ-दछेच्नु-अद-दछेच्नु', 0, true],
219219
]

0 commit comments

Comments
 (0)
0