Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#20198) Convert boolean values to integer values for the value attribute #20204

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Yii Framework 2 Change Log
- Bug #16116: Codeception: oci does not support enabling/disabling integrity check (@terabytesoftw)
- Bug #20191: Fix `ActiveRecord::getDirtyAttributes()` for JSON columns with multi-dimensional array values (brandonkelly)
- Bug #20175: Fix bad result for pagination when used with GridView (@lav45)
- Enh #20198: Boolean values of the `value` HTML attribute are now converted to integer values (@s1lver)


2.0.50 May 30, 2024
Expand Down
4 changes: 3 additions & 1 deletion framework/helpers/BaseHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -2003,8 +2003,10 @@
$html = '';
foreach ($attributes as $name => $value) {
if (is_bool($value)) {
if ($value) {
if ($value && 'value' !== $name) {

Check warning on line 2006 in framework/helpers/BaseHtml.php

View check run for this annotation

Codecov / codecov/patch

framework/helpers/BaseHtml.php#L2006

Added line #L2006 was not covered by tests
$html .= " $name";
} elseif ('value' === $name) {
$html .= " $name=\"" . static::encode((int)$value) . '"';

Check warning on line 2009 in framework/helpers/BaseHtml.php

View check run for this annotation

Codecov / codecov/patch

framework/helpers/BaseHtml.php#L2008-L2009

Added lines #L2008 - L2009 were not covered by tests
}
} elseif (is_array($value)) {
if (in_array($name, static::$dataAttributes)) {
Expand Down
10 changes: 10 additions & 0 deletions tests/framework/helpers/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,16 @@ public function testRenderTagAttributes()
$this->assertEquals('', Html::renderTagAttributes(['class' => []]));
$this->assertEquals(' style="width: 100px; height: 200px;"', Html::renderTagAttributes(['style' => ['width' => '100px', 'height' => '200px']]));
$this->assertEquals('', Html::renderTagAttributes(['style' => []]));
$this->assertEquals(' type="submit" value="1"', Html::renderTagAttributes(['type' => 'submit', 'value' => true]));
$this->assertEquals(' type="submit" value="0"', Html::renderTagAttributes(['type' => 'submit', 'value' => false]));
$this->assertEquals(
' type="submit" value="1" disabled',
Html::renderTagAttributes(['type' => 'submit', 'value' => true, 'disabled' => true])
);
$this->assertEquals(
' type="submit" value="0"',
Html::renderTagAttributes(['type' => 'submit', 'value' => false, 'disabled' => false])
);

$attributes = [
'data' => [
Expand Down
Loading