diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 536eb21b09..58651691bb 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -19,6 +19,7 @@ Yii Framework 2 Change Log - Bug #11066: `yii.js` - fixed `getQueryParams()` function to handle URLs with anchors correctly (DrDeath72) - Bug #11093: Fixed `yii\db\QueryBuilder::buildAndCondition()` to add query params passed directly by `yii\db\Expression` (CedricYii, silverfire) - Bug #11012: Fixed `yii\web\UploadedFile::getBaseName()` to work with UTF-8 file names (hiscaler, silverfire) +- Bug #11026: Fixed `StringHelper::truncateWords()` to count words properly for non-English text (samdark, tol17) - Bug #11040: Check parameter 'recursive' and disable recursive copying with option 'recursive' => false in method BaseFileHelper::copyDirectory (Ni-san) - Bug #11125: Fixed `JSON_ERROR_SYNTAX` for `json_decode(null)` in PHP 7 (fps01) - Bug #11188: Fixed wrong index usage in `CaptchaAction` when calling `imagefilledrectangle` (alsopub) diff --git a/framework/helpers/BaseStringHelper.php b/framework/helpers/BaseStringHelper.php index 2a0a722c44..864210e378 100644 --- a/framework/helpers/BaseStringHelper.php +++ b/framework/helpers/BaseStringHelper.php @@ -165,7 +165,7 @@ class BaseStringHelper } elseif ($token instanceof \HTMLPurifier_Token_Text && $totalCount <= $count) { //Text if (false === $encoding) { $token->data = self::truncateWords($token->data, $count - $totalCount, ''); - $currentCount = str_word_count($token->data); + $currentCount = self::countWords($token->data); } else { $token->data = self::truncate($token->data, $count - $totalCount, '', $encoding) . ' '; $currentCount = mb_strlen($token->data, $encoding); diff --git a/tests/framework/helpers/StringHelperTest.php b/tests/framework/helpers/StringHelperTest.php index 3f35b53c47..318e8db7f9 100644 --- a/tests/framework/helpers/StringHelperTest.php +++ b/tests/framework/helpers/StringHelperTest.php @@ -122,6 +122,7 @@ class StringHelperTest extends TestCase // With Html $this->assertEquals('This is a test...', StringHelper::truncateWords('This is a test sentance', 4, '...', true)); $this->assertEquals('This is a test...', StringHelper::truncateWords('This is a test sentance', 4, '...', true)); + $this->assertEquals('

раз два три четыре пять

шесть

...', StringHelper::truncateWords('

раз два три четыре пять

шесть семь восемь девять десять

', 6, '...', true)); } /**