Simplified code, enhanced PHPDocs

This commit is contained in:
SilverFire - Dmitry Naumenko
2018-03-10 10:19:07 +02:00
parent e72c31dc0b
commit b3f54d1065
3 changed files with 9 additions and 9 deletions

View File

@ -4,7 +4,7 @@ Yii Framework 2 Change Log
2.0.14.2 under development
------------------------
- Bug #15858: Fixed array undefined offset error calling Html::errorSummary with same error messages from different model attributes (FabrizioCaldarelli)
- Bug #15858: Fixed `Undefined offset` error calling `yii\helpers\Html::errorSummary()` with the same error messages for different model attributes (FabrizioCaldarelli, silverfire)
- Bug #15783: Regenerate CSRF token only when logging in directly (samdark)
- Bug #15801: Fixed `has-error` CSS class assignment in `yii\widgets\ActiveField` when attribute name is prefixed with tabular index (FabrizioCaldarelli)
- Bug #15792: Added missing `yii\db\QueryBuilder::conditionClasses` setter (silverfire)

View File

@ -1255,14 +1255,13 @@ class BaseHtml
$lines = array_unique(array_merge($lines, $model->getErrorSummary($showAllErrors)));
}
// Fix #15858 (FlorinRo) - If there are same message errors for different attributes, array_unique could skip some array key,
// so the next for cycle could fail because key missing.
// Applying array_values reorder array keys.
// If there are the same error messages for different attributes, array_unique will leave gaps
// between sequential keys. Applying array_values to reorder array keys.
$lines = array_values($lines);
if ($encode) {
for ($i = 0, $linesCount = count($lines); $i < $linesCount; $i++) {
$lines[$i] = Html::encode($lines[$i]);
foreach ($lines as &$line) {
$line = Html::encode($line);
}
}

View File

@ -1320,8 +1320,9 @@ EOD;
}
/**
* Test that attributes that output same errors, return unique message error
*/
* Test that attributes that output same errors, return unique message error
* @see https://github.com/yiisoft/yii2/pull/15859
*/
public function testCollectError()
{
$model = new DynamicModel(compact('attr1', 'attr2'));
@ -1333,7 +1334,7 @@ EOD;
$this->assertEquals(
'<div><p>Please fix the following errors:</p><ul><li>error1</li>
<li>error2</li></ul></div>',
Html::errorSummary($model,['showAllErrors'=>true])
Html::errorSummary($model, ['showAllErrors' => true])
);
}