19324 dropdownlist selection for boolean attributes (#19331)

* Fix #19324 by allowing for direct comparison

* Invert meaning of strict

* Remove WinterSilence from authors list

* Fix improper implementation of strict checks

* Add test for renderSelectOptions

* Partially revert 'Fix improper implementation of strict checks'

* Add additional tests for strict

* Revert 'Fix improper implementation of strict checks'

* Add failing test for demonstration

* Comment out demonstration test

* Update framework/CHANGELOG.md

Co-authored-by: Bizley <pawel@positive.codes>

Co-authored-by: Bizley <pawel@positive.codes>
This commit is contained in:
Adnan
2022-04-11 09:44:48 +02:00
committed by GitHub
parent 16a684e8e6
commit 94dfccd6fa
3 changed files with 48 additions and 1 deletions

View File

@ -16,6 +16,7 @@ Yii Framework 2 Change Log
- Enh #19304: Add filtering validator `yii\validators\TrimValidator` (WinterSilence)
- Enh #19309: Optimize `yii\base\Model::attributes()` (WinterSilence)
- Bug #19322: Revert force setting value to empty string in case it's `null` in `yii\validators\FilterValidator::validateAttribute()` (bizley)
- Bug #19324: Fix `yii\helpers\BaseHtml::renderSelectOptions()` giving wrong selection for boolean attributes (adnandautovic)
- Bug #19329: Fix `yii\web\GroupUrlRule` to properly normalize prefix (bizley)
- Bug #19328: Passing null to parameter #1 ($string) of type string is deprecated in `yii\db\oci\Schema` (Arkeins)
- Bug #19237: Fix OCI PHP 8.1 passing `null` to trim() (longthanhtran)

View File

@ -1914,7 +1914,7 @@ class BaseHtml
$attrs['value'] = (string) $key;
if (!array_key_exists('selected', $attrs)) {
$attrs['selected'] = $selection !== null &&
(!ArrayHelper::isTraversable($selection) && !strcmp($key, $selection)
(!ArrayHelper::isTraversable($selection) && ($strict ? !strcmp($key, $selection) : $selection == $key)
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn((string)$key, $selection, $strict));
}
$text = $encode ? static::encode($value) : $value;