-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duotone: Use the style engine to generate CSS for Duotone #48281
Duotone: Use the style engine to generate CSS for Duotone #48281
Conversation
Flaky tests detected in e1ab155. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4240273800
|
Agreed. This allow urls declaration isn't filterable. |
lib/experimental/kses.php
Outdated
* @param string $css_test_string The CSS to test. | ||
*/ | ||
function allow_filter_in_styles( $allow_css, $css_test_string ) { | ||
if ( strpos( $css_test_string, "filter: url('#wp-duotone" ) !== false ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: does this mean I could create a CSS string that included "filter: url('#wp-duotone"
in order to allow any CSS rule to bypass the filtering rules.
Assume we'll want to ditch this asap in order to get the Core patch landed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we should
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but it's not in order to get the core patch landed. the core patch should land for the reasons described by @scruffian in the ticket. This is here so we can work on this without core trunk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In core, when a url attribute is used, the value is parsed with some more complex regex (here: https://github.com/WordPress/wordpress-develop/blob/365efb13c2f2f9de572e53a4c115a0d59232e54f/src/wp-includes/kses.php#L2525). Would it be safer to copy + paste the regexes from there so that we can ensure the same level of parsing occurs for the the filter:
rule?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ( strpos( $css_test_string, "filter: url('#wp-duotone" ) !== false ) { | |
if ( preg_match( "^filter: url\('#wp-[-a-zA-Z0-9]+'\);$", $css_test_string ) ) { |
Might be a bit safer to use a a regex and only allow 100% correct urls rather than just a strpos check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like an elegant way to do it 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't test that regex, so it might need some tweaks if it isn't processing line by line or newlines have already been stripped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point. I think the string in preg_match
will need a/
delimiter at the beginning and end, too, to flag that it's a pattern, but overall I think that's a better and simpler way to do it than copying the more complex regex from core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm with a good preg match we could in theory even live with this in the plugin for a while.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in e1ab155
Thanks for the fixes @draganescu, I'm happy for this to merge if you are :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this and see where it gets us!
…()`. CSS filters can accept `url()` as a reference to an SVG filter element: {{{ filter: url( file.svg#filter-element-id ); }}} This commit allows for that syntax to be used in inline CSS. Original PR from Gutenberg repository: * [WordPress/gutenberg#48281 #48281 Duotone: Use the style engine to generate CSS for Duotone] References: * [https://developer.mozilla.org/en-US/docs/Web/CSS/filter MDN Web Docs: filter()] * [https://developer.mozilla.org/en-US/docs/Web/CSS/url MDN Web Docs: url()] Follow-up to [44136], [52049]. Props scruffian, jeryj, ironprogrammer, azaozz, hellofromTonya, SergeyBiryukov. Fixes #57780. Built from https://develop.svn.wordpress.org/trunk@55564 git-svn-id: http://core.svn.wordpress.org/trunk@55076 1a063a9b-81f0-0310-95a4-ce76da25c4cd
…()`. CSS filters can accept `url()` as a reference to an SVG filter element: {{{ filter: url( file.svg#filter-element-id ); }}} This commit allows for that syntax to be used in inline CSS. Original PR from Gutenberg repository: * [WordPress/gutenberg#48281 #48281 Duotone: Use the style engine to generate CSS for Duotone] References: * [https://developer.mozilla.org/en-US/docs/Web/CSS/filter MDN Web Docs: filter()] * [https://developer.mozilla.org/en-US/docs/Web/CSS/url MDN Web Docs: url()] Follow-up to [44136], [52049]. Props scruffian, jeryj, ironprogrammer, azaozz, hellofromTonya, SergeyBiryukov. Fixes #57780. Built from https://develop.svn.wordpress.org/trunk@55564 git-svn-id: https://core.svn.wordpress.org/trunk@55076 1a063a9b-81f0-0310-95a4-ce76da25c4cd
For visibility: Core support for URLs in CSS |
I created a follow to remove the filter but I think we'll need it for a while yet: #49488 |
What?
This changes the custom approach for block supports to use the style engine. This means that the CSS is output as part of the block supports CSS block rather than in its own inline style.
Why?
It's better to use the same code to generate CSS as its more efficient. It also will be slightly more performant as the output on the client is a little smaller.
How?
Using
gutenberg_style_engine_get_stylesheet_from_css_rules
Testing Instructions
Testing Instructions for Keyboard
Check that the image has CSS applied to it in the form:
filter: url('#wp-duotone-*') !important;
Note
Requires this core patch: WordPress/wordpress-develop#4108. I don't see a way to get this fix in to Gutenberg before its in core...