Skip to content

Commit e3625f2

Browse files
committed
bug #57616 [String] Revert "Fixed u()->snake(), b()->snake() and s()->snake() methods" (nicolas-grekas)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [String] Revert "Fixed u()->snake(), b()->snake() and s()->snake() methods" | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #57612 | License | MIT This PR reverts #57497 for BC reasons, but keeps the test cases we added in the process. Those test cases allowed to spot a real issue where the ascii and unicode implementations didn't agree on the resulting camel case for `SYMFONY IS GREAT`. Both implementations now result in `SYMFONYISGREAT` (likely introduced in #47423). Commits ------- 6397c38 [String] Revert "Fixed u()->snake(), b()->snake() and s()->snake() methods"
2 parents 4e57b84 + 6397c38 commit e3625f2

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/Symfony/Component/String/AbstractUnicodeString.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function ascii(array $rules = []): self
162162
public function camel(): parent
163163
{
164164
$str = clone $this;
165-
$str->string = str_replace(' ', '', preg_replace_callback('/\b.(?![A-Z]{2,})/u', static function ($m) use (&$i) {
165+
$str->string = str_replace(' ', '', preg_replace_callback('/\b.(?!\p{Lu})/u', static function ($m) use (&$i) {
166166
return 1 === ++$i ? ('İ' === $m[0] ? '' : mb_strtolower($m[0], 'UTF-8')) : mb_convert_case($m[0], \MB_CASE_TITLE, 'UTF-8');
167167
}, preg_replace('/[^\pL0-9]++/u', ' ', $this->string)));
168168

@@ -366,8 +366,8 @@ public function reverse(): parent
366366

367367
public function snake(): parent
368368
{
369-
$str = clone $this;
370-
$str->string = preg_replace('/[ _]+/', '_', mb_strtolower(preg_replace(['/(\p{Lu}+)(\p{Lu}\p{Ll})/u', '/([\p{Ll}0-9])(\p{Lu})/u'], '\1 \2', $str->string), 'UTF-8'));
369+
$str = $this->camel();
370+
$str->string = mb_strtolower(preg_replace(['/(\p{Lu}+)(\p{Lu}\p{Ll})/u', '/([\p{Ll}0-9])(\p{Lu})/u'], '\1_\2', $str->string), 'UTF-8');
371371

372372
return $str;
373373
}

src/Symfony/Component/String/ByteString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ public function slice(int $start = 0, ?int $length = null): parent
366366

367367
public function snake(): parent
368368
{
369-
$str = clone $this;
370-
$str->string = preg_replace('/[ _]+/', '_', strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1 \2', $str->string)));
369+
$str = $this->camel();
370+
$str->string = strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1_\2', $str->string));
371371

372372
return $str;
373373
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ public static function provideCamel()
10461046
['symfonyIsGreat', 'symfony_is_great'],
10471047
['symfony5IsGreat', 'symfony_5_is_great'],
10481048
['symfonyIsGreat', 'Symfony is great'],
1049+
['SYMFONYISGREAT', 'SYMFONY_IS_GREAT'],
10491050
['symfonyIsAGreatFramework', 'Symfony is a great framework'],
10501051
['symfonyIsGREAT', '*Symfony* is GREAT!!'],
10511052
['SYMFONY', 'SYMFONY'],
@@ -1077,11 +1078,12 @@ public static function provideSnake()
10771078
['symfony_is_great', 'symfonyIsGREAT'],
10781079
['symfony_is_really_great', 'symfonyIsREALLYGreat'],
10791080
['symfony', 'SYMFONY'],
1080-
['symfony_is_great', 'SYMFONY IS GREAT'],
1081-
['symfony_is_great', 'SYMFONY_IS_GREAT'],
1081+
['symfonyisgreat', 'SYMFONY IS GREAT'],
1082+
['symfonyisgreat', 'SYMFONY_IS_GREAT'],
10821083
['symfony_is_great', 'symfony is great'],
1083-
['symfony_is_great', 'SYMFONY IS GREAT'],
1084-
['symfony_is_great', 'SYMFONY _ IS _ GREAT'],
1084+
['symfonyisgreat', 'SYMFONY IS GREAT'],
1085+
['symfonyisgreat', 'SYMFONY _ IS _ GREAT'],
1086+
['symfony_isgreat', 'Symfony IS GREAT!'],
10851087
];
10861088
}
10871089

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy