From 3ec32b87d4145faa07e17904bae169e03d819366 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Fri, 14 Oct 2022 14:55:35 +1100 Subject: [PATCH] Update 6.1 CSS filter to match core --- lib/compat/wordpress-6.1/blocks.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/compat/wordpress-6.1/blocks.php b/lib/compat/wordpress-6.1/blocks.php index b22fb1fe18aee8..cd61b70a07f09b 100644 --- a/lib/compat/wordpress-6.1/blocks.php +++ b/lib/compat/wordpress-6.1/blocks.php @@ -38,11 +38,15 @@ function gutenberg_safe_style_attrs_6_1( $attrs ) { */ function gutenberg_safecss_filter_attr_allow_css_6_1( $allow_css, $css_test_string ) { if ( false === $allow_css ) { - // Allow some CSS functions. - $css_test_string = preg_replace( '/\b(?:calc|min|max|minmax|clamp)\(((?:\([^()]*\)?|[^()])*)\)/', '', $css_test_string ); - - // Allow CSS var. - $css_test_string = preg_replace( '/\(?var\(--[\w\-\()[\]\,\s]*\)/', '', $css_test_string ); + /* + * Allow CSS functions like var(), calc(), etc. by removing them from the test string. + * Nested functions and parentheses are also removed, so long as the parentheses are balanced. + */ + $css_test_string = preg_replace( + '/\b(?:var|calc|min|max|minmax|clamp)(\((?:[^()]|(?1))*\))/', + '', + $css_test_string + ); // Check for any CSS containing \ ( & } = or comments, // except for url(), calc(), or var() usage checked above.