From cf1600411cbf71d1c28f81b64430b6319eef5f6e Mon Sep 17 00:00:00 2001 From: Long TRAN Date: Thu, 3 Feb 2022 21:23:47 +0700 Subject: [PATCH] Fix #19204: Support numbers in Inflector::camel2words --- framework/CHANGELOG.md | 1 + framework/helpers/BaseInflector.php | 2 +- tests/framework/helpers/InflectorTest.php | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 85605a0..054abdf 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -11,6 +11,7 @@ Yii Framework 2 Change Log - Enh #19171: Added `$pagination` and `$sort` to `\yii\rest\IndexAction` for easy configuration (rhertogh) - Bug #19187: Fix `yii\filters\PageCache` to store original headers names instead of normalized ones (bizley) - Bug #19191: Change `\Exception` to `\Throwable` in `BadRequestHttpException` and `HttpException` (Dmitrijlin) +- Bug #19204: Support numbers in Inflector::camel2words (longthanhtran) 2.0.44 December 30, 2021 diff --git a/framework/helpers/BaseInflector.php b/framework/helpers/BaseInflector.php index 4cad3f9..65ec4ef 100644 --- a/framework/helpers/BaseInflector.php +++ b/framework/helpers/BaseInflector.php @@ -373,7 +373,7 @@ class BaseInflector { // 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 = preg_replace('/(?<=\p{Ll})\p{Lu}|(?<=[\p{L}\d])\p{Lu}(?=\p{Ll})|(\d+)/u', ' \0', $name); $label = mb_strtolower(trim(str_replace(['-', '_', '.'], ' ', $label)), self::encoding()); diff --git a/tests/framework/helpers/InflectorTest.php b/tests/framework/helpers/InflectorTest.php index dd56d86..5a91996 100644 --- a/tests/framework/helpers/InflectorTest.php +++ b/tests/framework/helpers/InflectorTest.php @@ -121,6 +121,9 @@ class InflectorTest extends TestCase $this->assertEquals('Foo Bar', Inflector::camel2words('foo BAR')); $this->assertEquals('Foo Bar', Inflector::camel2words('Foo Bar')); $this->assertEquals('Foo Bar', Inflector::camel2words('FOO BAR')); + $this->assertEquals('Order 4 Other Phones', Inflector::camel2words('Order4OtherPhones')); + $this->assertEquals('I Have 23 Dogs', Inflector::camel2words('IHave23Dogs')); + $this->assertEquals('Con Chó Cười 34 Lần', Inflector::camel2words('ConChóCười34Lần')); } public function testCamel2id()