Skip to content

menu.html.twig: avoid rendering empty style attribute in menu badges …#7510

Open
bt-nn wants to merge 2 commits intoEasyCorp:5.xfrom
bt-nn:patch-4
Open

menu.html.twig: avoid rendering empty style attribute in menu badges …#7510
bt-nn wants to merge 2 commits intoEasyCorp:5.xfrom
bt-nn:patch-4

Conversation

@bt-nn
Copy link
Contributor

@bt-nn bt-nn commented Mar 18, 2026

…(CSP compatibility)

EasyAdmin always rendered a style attribute for menu item badges, even when item.badge.htmlStyle was empty. This produced style="", which still counts as inline CSS and violates strict Content Security Policies (CSP) that do not allow unsafe-inline.
The style attribute is now only rendered when a non-empty value is provided.

bt-nn added 2 commits March 18, 2026 13:53
…(CSP compatibility)

EasyAdmin always rendered a `style` attribute for menu item badges, even when `item.badge.htmlStyle` was empty. This produced `style=""`, which still counts as inline CSS and violates strict Content Security Policies (CSP) that do not allow `unsafe-inline`.
The style attribute is now only rendered when a non-empty value is provided.
</span>
{% if item.badge %}
<span class="menu-item-badge rounded-pill badge {{ item.badge.cssClass }}" {{ _self.render_html_attributes(item.badge) }} style="{{ item.badge.htmlStyle }}">{{ item.badge.content }}</span>
<span class="menu-item-badge rounded-pill badge {{ item.badge.cssClass }}" {{ _self.render_html_attributes(item.badge) }} {{ item.badge.htmlStyle ? 'style="' ~ item.badge.htmlStyle ~ '"' : '' }}">{{ item.badge.content }}</span>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant we just rename htmlStyle to style, so this attribute will be rendered by render_html_attributes()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants