Formatting: add a new 'safe_style_disallowed_chars' filter.

Enable developers to change the regex used in `safecss_filter_attr` to limit characters in the parsed CSS.

Props paulschreiber, swissspidy, rmccue, bartekcholewa, miinasikk.
Fixes #37134.



git-svn-id: https://develop.svn.wordpress.org/trunk@47891 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Adam Silverstein
2020-06-02 23:44:40 +00:00
parent e18d6e942b
commit fa96d59318
2 changed files with 111 additions and 7 deletions
+17 -6
View File
@@ -2301,13 +2301,24 @@ function safecss_filter_attr( $css, $deprecated = '' ) {
}
}
// Remove any CSS containing containing \ ( & } = or comments, except for url() useage checked above.
if ( $found && ! preg_match( '%[\\\(&=}]|/\*%', $css_test_string ) ) {
if ( '' !== $css ) {
$css .= ';';
if ( $found ) {
/**
* Filters the regex limiting the list of characters not allowed in CSS rules.
*
* Default behaviour is to remove any css containing \ ( & } = or comments, except for url() usage.
*
* @since 5.5.0
*
* @param string $regex Regex pattern of disallowed characters in CSS rules. Default is '%[\\\(&=}]|/\*%'.
* @param string $css_test_string CSS value to test.
*/
$disallowed_chars = apply_filters( 'safe_style_disallowed_chars', '%[\\\(&=}]|/\*%', $css_test_string );
if ( ! preg_match( $disallowed_chars, $css_test_string ) ) {
if ( '' !== $css ) {
$css .= ';';
}
$css .= $css_item;
}
$css .= $css_item;
}
}