Skip to content

Commit 2b7f865

Browse files
committed
KSES: Add support for CSS repeat() function.
Introduces support for the CSS `repeat()` function to support complex grid layouts. Props isabel_brison, azaozz. Fixes #58551. git-svn-id: https://develop.svn.wordpress.org/trunk@55944 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6966e31 commit 2b7f865

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/wp-includes/kses.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ function kses_init() {
22792279
* Extended `margin-*` and `padding-*` support for logical properties.
22802280
* @since 6.2.0 Added support for `aspect-ratio`, `position`, `top`, `right`, `bottom`, `left`,
22812281
* and `z-index` CSS properties.
2282-
* @since 6.3.0 Extended support for `filter` to accept a URL.
2282+
* @since 6.3.0 Extended support for `filter` to accept a URL and added support for repeat().
22832283
*
22842284
* @param string $css A string of CSS rules.
22852285
* @param string $deprecated Not used.
@@ -2563,7 +2563,7 @@ function safecss_filter_attr( $css, $deprecated = '' ) {
25632563
* Nested functions and parentheses are also removed, so long as the parentheses are balanced.
25642564
*/
25652565
$css_test_string = preg_replace(
2566-
'/\b(?:var|calc|min|max|minmax|clamp)(\((?:[^()]|(?1))*\))/',
2566+
'/\b(?:var|calc|min|max|minmax|clamp|repeat)(\((?:[^()]|(?1))*\))/',
25672567
'',
25682568
$css_test_string
25692569
);

tests/phpunit/tests/kses.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ public function test_wp_kses_attr_no_attributes_allowed_with_false() {
937937
* @ticket 48376
938938
* @ticket 55966
939939
* @ticket 56122
940+
* @ticket 58551
940941
* @dataProvider data_safecss_filter_attr
941942
*
942943
* @param string $css A string of CSS rules.
@@ -1047,9 +1048,9 @@ public function data_safecss_filter_attr() {
10471048
'css' => 'grid-template-rows: 40px 4em 40px;grid-auto-rows: min-content;grid-row-start: -1;grid-row-end: 3;grid-row-gap: 1em',
10481049
'expected' => 'grid-template-rows: 40px 4em 40px;grid-auto-rows: min-content;grid-row-start: -1;grid-row-end: 3;grid-row-gap: 1em',
10491050
),
1050-
// `grid` does not yet support functions or `\`.
1051+
// `grid` does not yet support `\`.
10511052
array(
1052-
'css' => 'grid-template-columns: repeat(2, 50px 1fr);grid-template: 1em / 20% 20px 1fr',
1053+
'css' => 'grid-template: 1em / 20% 20px 1fr',
10531054
'expected' => '',
10541055
),
10551056
// `flex` and `grid` alignments introduced in 5.3.
@@ -1321,6 +1322,25 @@ public function data_safecss_filter_attr() {
13211322
'css' => 'filter: url( my-file.svg#svg-blur );',
13221323
'expected' => 'filter: url( my-file.svg#svg-blur )',
13231324
),
1325+
// Support for `repeat` function.
1326+
array(
1327+
'css' => 'grid-template-columns: repeat(4, minmax(0, 1fr))',
1328+
'expected' => 'grid-template-columns: repeat(4, minmax(0, 1fr))',
1329+
),
1330+
array(
1331+
'css' => 'grid-template-columns: repeat(auto-fill, minmax(min(12rem, 100%), 1fr))',
1332+
'expected' => 'grid-template-columns: repeat(auto-fill, minmax(min(12rem, 100%), 1fr))',
1333+
),
1334+
// Malformed repeat, no closing `)`.
1335+
array(
1336+
'css' => 'grid-template-columns: repeat(4, minmax(0, 1fr)',
1337+
'expected' => '',
1338+
),
1339+
// Malformed repeat, contains unsupported function.
1340+
array(
1341+
'css' => 'grid-template-columns: repeat(4, unsupported(0, 1fr)',
1342+
'expected' => '',
1343+
),
13241344
);
13251345
}
13261346

0 commit comments

Comments
 (0)