Skip to content

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

Merged
javiereguiluz merged 1 commit intoEasyCorp:4.xfrom
bt-nn:patch-4
Mar 30, 2026
Merged

menu.html.twig: avoid rendering empty style attribute in menu badges …#7510
javiereguiluz merged 1 commit intoEasyCorp:4.xfrom
bt-nn:patch-4

Conversation

@bt-nn
Copy link
Copy Markdown
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.

Comment thread templates/menu.html.twig
</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
Copy Markdown
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()?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to keep the more explicit htmlStyle name for the HTML style attribute becaus ewe use style for the variant of the badge (primary, success, danger, etc.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or inside the render_html_attributes function, it may be handled automatically if htmlStyle is found

@javiereguiluz javiereguiluz added this to the 4.x milestone Mar 30, 2026
@javiereguiluz javiereguiluz changed the base branch from 5.x to 4.x March 30, 2026 18:48
@javiereguiluz
Copy link
Copy Markdown
Collaborator

Thanks for fixing this bug @bt-nn.

@javiereguiluz javiereguiluz merged commit 7050bbe into EasyCorp:4.x Mar 30, 2026
18 checks passed
@bt-nn
Copy link
Copy Markdown
Contributor Author

bt-nn commented Mar 31, 2026

Thanks for merging

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants