Skip to content

Commit 0e6cd07

Browse files
committed
normalize underscores in snake()
1 parent d38d44f commit 0e6cd07

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
@@ -367,7 +367,7 @@ public function reverse(): parent
367367
public function snake(): parent
368368
{
369369
$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', $str->string), 'UTF-8'));
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'));
371371

372372
return $str;
373373
}

src/Symfony/Component/String/ByteString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public function slice(int $start = 0, ?int $length = null): parent
367367
public function snake(): parent
368368
{
369369
$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)));
370+
$str->string = preg_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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,9 @@ public static function provideSnake()
10791079
['symfony', 'SYMFONY'],
10801080
['symfony_is_great', 'SYMFONY IS GREAT'],
10811081
['symfony_is_great', 'SYMFONY_IS_GREAT'],
1082+
['symfony_is_great', 'symfony is great'],
1083+
['symfony_is_great', 'SYMFONY IS GREAT'],
1084+
['symfony_is_great', 'SYMFONY _ IS _ GREAT'],
10821085
];
10831086
}
10841087

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