From 1416dbcc7b064a7cfb35cad6d28aef1eb6d2cb8f Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Thu, 4 Aug 2022 16:12:07 +0200 Subject: [PATCH] [String] Fix snake conversion --- src/Symfony/Component/String/AbstractUnicodeString.php | 2 +- src/Symfony/Component/String/ByteString.php | 2 +- src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/String/AbstractUnicodeString.php b/src/Symfony/Component/String/AbstractUnicodeString.php index a482300d28682..6fd418e65afe9 100644 --- a/src/Symfony/Component/String/AbstractUnicodeString.php +++ b/src/Symfony/Component/String/AbstractUnicodeString.php @@ -366,7 +366,7 @@ public function reverse(): parent public function snake(): parent { - $str = $this->camel()->title(); + $str = $this->camel(); $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'); return $str; diff --git a/src/Symfony/Component/String/ByteString.php b/src/Symfony/Component/String/ByteString.php index bbf8614cf7be6..d9ee3edb52cb2 100644 --- a/src/Symfony/Component/String/ByteString.php +++ b/src/Symfony/Component/String/ByteString.php @@ -363,7 +363,7 @@ public function slice(int $start = 0, int $length = null): parent public function snake(): parent { - $str = $this->camel()->title(); + $str = $this->camel(); $str->string = strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1_\2', $str->string)); return $str; diff --git a/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php b/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php index d28cfb6f53d78..b3c3d9086e1e6 100644 --- a/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php +++ b/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php @@ -1041,6 +1041,7 @@ public static function provideCamel() { return [ ['', ''], + ['xY', 'x_y'], ['symfonyIsGreat', 'symfony_is_great'], ['symfony5IsGreat', 'symfony_5_is_great'], ['symfonyIsGreat', 'Symfony is great'], @@ -1063,6 +1064,8 @@ public static function provideSnake() { return [ ['', ''], + ['x_y', 'x_y'], + ['x_y', 'X_Y'], ['symfony_is_great', 'symfonyIsGreat'], ['symfony5_is_great', 'symfony5IsGreat'], ['symfony5is_great', 'symfony5isGreat'],