8000 bug #57497 [String] Fixed u()->snake(), b()->snake() and s()->snake()… · symfony/symfony@6517957 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6517957

Browse files
bug #57497 [String] Fixed u()->snake(), b()->snake() and s()->snake() methods (arczinosek)
This PR was merged into the 5.4 branch. Discussion ---------- [String] Fixed u()->snake(), b()->snake() and s()->snake() methods | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #57464 | License | MIT [String] ByteString::snake and AbstractUnitcodeString::snake methods doesn't convert all uppercase words in the right way. For example, string "GREAT SYMFONY" is converted to "greatsymfony" instead of "great_symfony". Commits ------- f93113e [String] Fix *String::snake methods
2 parents 572ce41 + f93113e commit 6517957

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/Symfony/Component/String/AbstractUnicodeString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ public function reverse(): parent
366366

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

372372
return $str;
373373
}

src/Symfony/Component/String/ByteString.php

Lines changed: 2 additions & 2 deletions
9156
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 = $this->camel();
370-
$str->string = strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1_\2', $str->string));
369+
$str = clone $this;
370+
$str->string = str_replace(' ', '_', 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,8 @@ public static function provideSnake()
10771077
['symfony_is_great', 'symfonyIsGREAT'],
10781078
['symfony_is_really_great', 'symfonyIsREALLYGreat'],
10791079
['symfony', 'SYMFONY'],
1080+
['symfony_is_great', 'SYMFONY IS GREAT'],
1081+
['symfony_is_great', 'SYMFONY_IS_GREAT'],
10801082
];
10811083
}
10821084

0 commit comments

Comments
 (0)
0