KSES: Allow SVG-specific presentation attributes in safe_style_css#79172
KSES: Allow SVG-specific presentation attributes in safe_style_css#79172t-hamano wants to merge 2 commits into
Conversation
Icon SVG markup uses inline styles such as `style="fill: none"`, but `wp_kses()` strips them because `safecss_filter_attr()` only keeps an allowlist of CSS properties that does not include SVG presentation attributes. Add a single `safe_style_css` filter that allowlists the SVG-specific presentation attributes so they survive sanitization, replacing the per-call workaround in the icons registry. Co-Authored-By: Claude <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Flaky tests detected in 9f9b1b3. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27469026092
|
See #78808 (comment)
What?
Adds a
safe_style_cssfilter that allowlists SVG-specific presentation attributes so they are preserved when SVG markup is sanitized withwp_kses().Why?
wp_kses()runs thestyleattribute throughsafecss_filter_attr(), which only keeps an allowlist of CSS properties. SVG presentation attributes are not in that list, so inline styles get stripped during sanitization.This issue may become more prominent once stroke-based icons are implemented by #78808 or custom icons are allowed to be registered by #77260.
How?
Adds
lib/compat/wordpress-7.1/kses.phpwith a singlesafe_style_cssfilter that appends the SVG presentation attributes. The list is based on the SVG presentation attributes documented on MDN.Testing Instructions
Confirm that the styles are not removed when using the code above.
Use of AI Tools
This PR was authored with the assistance of Claude Code. All changes were reviewed by the author.