Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e178fe

Browse files
committed
[String] Fix snake conversion
1 parent f9d5e24 commit 7e178fe

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/Symfony/Component/String/AbstractUnicodeString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public function reverse(): static
348348

349349
public function snake(): static
350350
{
351-
$str = $this->camel()->title();
351+
$str = $this->camel();
352352
$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');
353353

354354
return $str;

src/Symfony/Component/String/ByteString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public function slice(int $start = 0, int $length = null): static
339339

340340
public function snake(): static
341341
{
342-
$str = $this->camel()->title();
342+
$str = $this->camel();
343343
$str->string = strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1_\2', $str->string));
344344

345345
return $str;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ public static function provideCamel()
10411041
{
10421042
return [
10431043
['', ''],
1044+
['xY', 'x_y'],
10441045
['symfonyIsGreat', 'symfony_is_great'],
10451046
['symfony5IsGreat', 'symfony_5_is_great'],
10461047
['symfonyIsGreat', 'Symfony is great'],
@@ -1063,6 +1064,8 @@ public static function provideSnake()
10631064
{
10641065
return [
10651066
['', ''],
1067+
['x_y', 'x_y'],
1068+
['x_y', 'X_Y'],
10661069
['symfony_is_great', 'symfonyIsGreat'],
10671070
['symfony5_is_great', 'symfony5IsGreat'],
10681071
['symfony5is_great', 'symfony5isGreat'],

0 commit comments

Comments
 (0)