diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index c50dcc6765..0618f5a667 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -12,6 +12,7 @@ Yii Framework 2 Change Log - Bug #12539: `yii\filters\ContentNegotiator` now generates 406 'Not Acceptable' instead of 415 'Unsupported Media Type' on content-type negotiation fail (PowerGamer1) - Bug #17760: Fix `JSON::encode()` for `\DateTimeInterface` under PHP 7.4 (samdark) - Enh #17792: Added support for `aria` attributes to `yii\helpers\BaseHtml::renderTagAttributes()` (brandonkelly) +- Bug #17793: Fix inconsistent handling of null `data` attribute values in `yii\helpers\BaseHtml::renderTagAttributes()` (brandonkelly) 2.0.31 December 18, 2019 diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php index 4a8d603a26..3c84497309 100644 --- a/framework/helpers/BaseHtml.php +++ b/framework/helpers/BaseHtml.php @@ -1961,7 +1961,7 @@ class BaseHtml if ($v) { $html .= " $name-$n"; } - } else { + } elseif ($v !== null) { $html .= " $name-$n=\"" . static::encode($v) . '"'; } } diff --git a/tests/framework/helpers/HtmlTest.php b/tests/framework/helpers/HtmlTest.php index 41a247bb8b..6bd51ccbab 100644 --- a/tests/framework/helpers/HtmlTest.php +++ b/tests/framework/helpers/HtmlTest.php @@ -1028,6 +1028,14 @@ EOD; ], ]; $this->assertEquals('', Html::renderTagAttributes($attributes)); + + + $attributes = [ + 'data' => [ + 'foo' => null, + ], + ]; + $this->assertEquals('', Html::renderTagAttributes($attributes)); } public function testAddCssClass()