Icons: keep fill and stroke on the sanitized <svg> root - #81011
Closed
retrofox wants to merge 1 commit into
Closed
Conversation
override the sanitizer allow-list; mirror the compat copy
17 tasks
Contributor
Author
|
closing in favor of #75550 |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
sanitize_icon_content()stripsfillandstrokefrom the root<svg>, so registered icon content losesfill="currentColor"and stops inheriting the surrounding color. Every icon inpackages/iconsdeclares 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_GutenbergOverrides
sanitize_icon_content()withfillandstrokeallowed on thesvgroot.Compat
Mirrors the allow-list change in
lib/compat/wordpress-7.0/class-wp-icons-registry.php.Tests
test_register_icon_keeps_root_color_attributesasserts both attributes survive registration.Testing
The root
<svg>carriesfill="currentColor".GET /wp/v2/icons/core/calendar:contentcarries the attribute as well.Run the registry tests:
Follow-ups
WP_Icons_Registrywith the 7.1 sync (Core-64847).