diff --git a/src/Symfony/Component/String/AbstractUnicodeString.php b/src/Symfony/Component/String/AbstractUnicodeString.php index 13ff7163eaeed..ddb81fa50b098 100644 --- a/src/Symfony/Component/String/AbstractUnicodeString.php +++ b/src/Symfony/Component/String/AbstractUnicodeString.php @@ -367,7 +367,9 @@ public function reverse(): parent public function snake(): parent { $str = clone $this; - $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')); + $str->string = preg_replace('/[^\pL0-9_ ]++/u', '', $str->string); + $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'); + $str->string = preg_replace('/[ _]+/', '_', $str->string); return $str; } diff --git a/src/Symfony/Component/String/ByteString.php b/src/Symfony/Component/String/ByteString.php index e4ad7a680f51b..1e9aaac221f7b 100644 --- a/src/Symfony/Component/String/ByteString.php +++ b/src/Symfony/Component/String/ByteString.php @@ -367,7 +367,9 @@ public function slice(int $start = 0, ?int $length = null): parent public function snake(): parent { $str = clone $this; - $str->string = preg_replace('/[ _]+/', '_', strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1 \2', $str->string))); + $str->string = preg_replace('/[^a-zA-Z0-9\x7f-\xff_ ]++/', '', $str->string); + $str->string = strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1 \2', $str->string)); + $str->string = preg_replace('/[ _]+/', '_', $str->string); return $str; } diff --git a/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php b/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php index 42e8fda6f026d..5f21a53e4a3f7 100644 --- a/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php +++ b/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php @@ -1082,6 +1082,7 @@ public static function provideSnake() ['symfony_is_great', 'symfony is great'], ['symfony_is_great', 'SYMFONY IS GREAT'], ['symfony_is_great', 'SYMFONY _ IS _ GREAT'], + ['symfony_is_great', 'Symfony is great.'], ]; } 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