Browse Source

Fix #18898: Fix `yii\helpers\Inflector::camel2words()` to work with words ending with 0

tags/2.0.44
Michaël Arnauts 3 years ago committed by GitHub
parent
commit
1d7f9d8d2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      framework/CHANGELOG.md
  2. 6
      framework/helpers/BaseStringHelper.php
  3. 2
      tests/framework/helpers/StringHelperTest.php

1
framework/CHANGELOG.md

@ -19,6 +19,7 @@ Yii Framework 2 Change Log
- Bug #18880: Fix `yii\helpers\ArrayHelper::toArray()` for `DateTime` objects in PHP >= 7.4 (rhertogh)
- Bug #18883: Fix `yii\web\HeaderCollection::fromArray()` now ensures lower case keys (rhertogh)
- Bug #18886: Fix default return of `yii\db\Migration::safeUp()` and `yii\db\Migration::safeDown()` (WinterSilence)
- Bug #18898: Fix `yii\helpers\Inflector::camel2words()` to work with words ending with 0 (michaelarnauts)
2.0.43 August 09, 2021

6
framework/helpers/BaseStringHelper.php

@ -48,7 +48,7 @@ class BaseStringHelper
if ($length === null) {
$length = static::byteLength($string);
}
return mb_substr($string, $start, $length, '8bit');
}
@ -71,7 +71,7 @@ class BaseStringHelper
if ($len > 0 && mb_substr($path, -$len) === $suffix) {
$path = mb_substr($path, 0, -$len);
}
$path = rtrim(str_replace('\\', '/', $path), '/');
$pos = mb_strrpos($path, '/');
if ($pos !== false) {
@ -468,7 +468,7 @@ class BaseStringHelper
}
$parts = preg_split('/(\s+[^\w]+\s+|^[^\w]+\s+|\s+)/u', $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
$ucfirstEven = !trim(mb_substr($parts[0], -1, 1, $encoding));
$ucfirstEven = trim(mb_substr($parts[0], -1, 1, $encoding)) === '';
foreach ($parts as $key => $value) {
$isEven = (bool)($key % 2);
if ($ucfirstEven === $isEven) {

2
tests/framework/helpers/StringHelperTest.php

@ -438,6 +438,8 @@ class StringHelperTest extends TestCase
['0', '0'],
[null, ''],
['здесь我 multibyte我 строка', 'Здесь我 Multibyte我 Строка'],
['p0 upload', 'P0 Upload'],
['p5 upload', 'P5 Upload'],
];
}

Loading…
Cancel
Save