Skip to content

Icons: keep fill and stroke on the sanitized <svg> root - #81011

Closed
retrofox wants to merge 1 commit into
trunkfrom
fix/icon-sanitizer-svg-fill
Closed

Icons: keep fill and stroke on the sanitized <svg> root#81011
retrofox wants to merge 1 commit into
trunkfrom
fix/icon-sanitizer-svg-fill

Conversation

@retrofox

Copy link
Copy Markdown
Contributor

What

sanitize_icon_content() strips fill and stroke from the root <svg>, so registered icon content loses fill="currentColor" and stops inheriting the surrounding color. Every icon in packages/icons declares it on the root.

This allows both attributes: an override in WP_Icons_Registry_Gutenberg, which is what runs with the plugin active, and the same change in the 7.0 compat copy. Core's copy needs the same two attributes when the iteration syncs.

Gap discussed in #75715 (comment), surfaced with screenshots in this review thread.

Why

Sanitized icons fall back to the default black fill: near-invisible against dark schemes, unresponsive to currentColor, and every consumer has to re-add the attribute client-side.

How

  • WP_Icons_Registry_Gutenberg
    Overrides sanitize_icon_content() with fill and stroke allowed on the svg root.

  • Compat
    Mirrors the allow-list change in lib/compat/wordpress-7.0/class-wp-icons-registry.php.

  • Tests
    test_register_icon_keeps_root_color_attributes asserts both attributes survive registration.

Testing

  1. With the plugin active, check a core icon keeps its fill:
wp eval 'echo wp_get_icon( "core/calendar" );'

The root <svg> carries fill="currentColor".

  1. GET /wp/v2/icons/core/calendar: content carries the attribute as well.

  2. Run the registry tests:

phpunit --filter Icons_Registry_Gutenberg

Follow-ups

  • Apply the same allow-list change to Core's WP_Icons_Registry with the 7.1 sync (Core-64847).

override the sanitizer allow-list; mirror the compat copy
@retrofox
retrofox requested a review from spacedmonkey as a code owner July 31, 2026 08:41
@retrofox retrofox added [Type] Bug An existing feature does not function as intended [Feature] Icons Related to Icon registration API and Icon REST API labels Jul 31, 2026
@retrofox retrofox self-assigned this Jul 31, 2026
@retrofox retrofox added [Type] Enhancement A suggestion for improvement. and removed [Type] Bug An existing feature does not function as intended labels Jul 31, 2026
@retrofox

Copy link
Copy Markdown
Contributor Author

closing in favor of #75550

@retrofox retrofox closed this Jul 31, 2026
@t-hamano

Copy link
Copy Markdown
Contributor

Since #75550 might not make it in time for 7.1, I think we can proceed with this PR first. Can you also prepare the core PR along with this one? The core ticket is here: https://core.trac.wordpress.org/ticket/64847

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

Labels

[Feature] Icons Related to Icon registration API and Icon REST API [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants