Skip to content

Commit

Permalink
Fixes yiisoft#14980: Fix looping in yii\i18n\MessageFormatter token…
Browse files Browse the repository at this point in the history
…ize pattern if pattern is invalid
  • Loading branch information
uaoleg authored and samdark committed Jan 17, 2018
1 parent 18281c2 commit ebd3d61
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Yii Framework 2 Change Log
- Bug #14903: Fixed route with extra dashes is executed controller while it should not (developeruz)
- Bug #14916: Fixed `yii\db\Query::each()` iterator key starts from 1 instead of 0 (Vovan-VE)
- Bug #15046: Throw an `yii\web\HeadersAlreadySentException` if headers were sent before web response (dmirogin)
- Bug #14980: Fix looping in `yii\i18n\MessageFormatter` tokenize pattern if pattern is invalid (uaoleg, developeruz)
- Bug #15142: Fixed array params replacing in `yii\helpers\BaseUrl::current()` (IceJOKER)
- Bug #15169: Fixed translating a string when NULL parameter is passed (developeruz)
- Bug #15194: Fixed `yii\db\QueryBuilder::insert()` to preserve passed params when building a `INSERT INTO ... SELECT` query for MSSQL, PostgreSQL and SQLite (sergeymakinen)
Expand Down
4 changes: 4 additions & 0 deletions framework/i18n/MessageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ private static function tokenizePattern($pattern)
$tokens[] = mb_substr($pattern, $start, $open - $start, $charset);
$start = $open;
}

if ($depth !== 0 && ($open === false || $close === false)) {
break;
}
}
if ($depth !== 0) {
return false;
Expand Down
11 changes: 9 additions & 2 deletions tests/framework/i18n/MessageFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,18 @@ public function patterns()
'offers',
[13],
],
[
'Message without {closing} {brace',
false, // Message pattern is invalid
['closing brace and with'],
],
[
'{gender, select, female{Уважаемая} other{Уважаемый}} {firstname},',
'Уважаемый Vadim,',
['gender' => null,
'firstname' => 'Vadim'],
[
'gender' => null,
'firstname' => 'Vadim'
],
],
];
}
Expand Down

0 comments on commit ebd3d61

Please sign in to comment.