Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd64a190

Browse files
committed
[String] Fix *String::snake methods
The ByteString::snake and AbstractUnitcodeString::snake methods had a bug that caused incorrect string conversion results for all uppercase words separated by space or "_" character.Ex. "GREAT SYMFONY" was converted to "greatsymfony" instead of "great_symfony"
1 parente79eea1 commitd64a190

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
publicfunctionsnake():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',$str->string),'UTF-8'));
371371

372372
return$str;
373373
}

‎src/Symfony/Component/String/ByteString.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ public function slice(int $start = 0, ?int $length = null): parent
366366

367367
publicfunctionsnake():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)

[8]ページ先頭

©2009-2025 Movatter.jp