Fix #18832 - Inflector::camel2words() adding extra spaces (#18833)

This commit is contained in:
Brandon Kelly
2021-08-14 01:43:23 -07:00
committed by GitHub
parent 463a67bc73
commit 63e93ba243
3 changed files with 10 additions and 5 deletions

View File

@ -7,6 +7,7 @@ Yii Framework 2 Change Log
- Enh #18826: Add ability to turn the sorting off for a clicked column in GridView with multisort (ditibal)
- Bug #18646: Remove stale identity data from session if `IdentityInterface::findIdentity()` returns `null` (mikehaertl)
- Bug #18832: Fix `Inflector::camel2words()` adding extra spaces (brandonkelly)
2.0.43 August 09, 2021

View File

@ -371,11 +371,11 @@ class BaseInflector
*/
public static function camel2words($name, $ucwords = true)
{
$label = mb_strtolower(trim(str_replace([
'-',
'_',
'.',
], ' ', preg_replace('/(?<!\p{Lu})(\p{Lu})|(\p{Lu})(?=\p{Ll})/u', ' \0', $name))), self::encoding());
// Add a space before any uppercase letter preceded by a lowercase letter (xY => x Y)
// and any uppercase letter preceded by an uppercase letter and followed by a lowercase letter (XYz => X Yz)
$label = preg_replace('/(?<=\p{Ll})\p{Lu}|(?<=\p{L})\p{Lu}(?=\p{Ll})/u', ' \0', $name);
$label = mb_strtolower(trim(str_replace(['-', '_', '.'], ' ', $label)), self::encoding());
return $ucwords ? StringHelper::mb_ucwords($label, self::encoding()) : $label;
}