Skip to content
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 CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 3.29.0 (2026-XX-XX)

* Fix `html_attr` dropping `style` declarations whose value is `0`, `0.0` or `'0'`
* Fix the `default` filter fallback emitting an undefined variable warning when it uses the null-safe operator
* Fix the `matches` operator silently treating PCRE execution errors as non-matches
* Add the `HtmlExtension::htmlAttrValue()` method to resolve a single HTML attribute value the way the `html_attr` function renders it
Expand Down
4 changes: 3 additions & 1 deletion extra/html-extra/HtmlAttr/InlineStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public function getValue(): ?string
{
$style = '';
foreach ($this->value as $name => $value) {
if (empty($value) || true === $value) {
// `0`, `0.0` and `'0'` are valid CSS values, so only the values that carry
// no declaration at all are skipped here
Comment thread
fabpot marked this conversation as resolved.
if (null === $value || false === $value || true === $value || '' === $value || [] === $value) {
continue;
}
if (is_numeric($name)) {
Expand Down
21 changes: 21 additions & 0 deletions extra/html-extra/Tests/HtmlAttrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,27 @@ public static function htmlAttrProvider(): \Generator
],
];

yield 'zero style declaration values are printed' => [
'style="opacity: 0; z-index: 0; margin: 0;"',
[
['style' => ['opacity' => 0, 'z-index' => '0', 'margin' => 0.0]],
],
];

yield 'null, false and empty string style declaration values are omitted' => [
'style="color: red;"',
[
['style' => ['a' => null, 'b' => false, 'c' => '', 'd' => true, 'color' => 'red']],
],
];

yield 'style attribute is omitted when every declaration is omitted' => [
'',
[
['style' => ['a' => null, 'b' => false, 'c' => '']],
],
];

yield 'merging style attributes overrides by key' => [
'style="color: blue; font-size: 14px;"',
[
Expand Down
Loading