Skip to content

Commit e904e28

Browse files
committed
KSES: Allow SVG presentation attributes in safe_style_css.
Add SVG presentation attributes to the list of CSS properties allowed by `safecss_filter_attr()`, so inline SVG markup can be styled via the `style` attribute. This ports Gutenberg PR #79172 to Core. Props afercia, westonruter, wildworks. Fixes #65457. git-svn-id: https://develop.svn.wordpress.org/trunk@62530 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 4e804fb commit e904e28

2 files changed

Lines changed: 104 additions & 0 deletions

File tree

src/wp-includes/kses.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,6 +2579,7 @@ function safecss_filter_attr( $css, $deprecated = '' ) {
25792579
* Filters the list of allowed CSS attributes.
25802580
*
25812581
* @since 2.8.1
2582+
* @since 7.1.0 Added support for SVG presentation attributes.
25822583
*
25832584
* @param string[] $attr Array of allowed CSS attributes.
25842585
*/
@@ -2737,6 +2738,71 @@ function safecss_filter_attr( $css, $deprecated = '' ) {
27372738
'aspect-ratio',
27382739
'container-type',
27392740

2741+
'fill',
2742+
'fill-opacity',
2743+
'fill-rule',
2744+
2745+
'stroke',
2746+
'stroke-dasharray',
2747+
'stroke-dashoffset',
2748+
'stroke-linecap',
2749+
'stroke-linejoin',
2750+
'stroke-miterlimit',
2751+
'stroke-opacity',
2752+
'stroke-width',
2753+
2754+
'color-interpolation',
2755+
'color-interpolation-filters',
2756+
'paint-order',
2757+
'stop-color',
2758+
'stop-opacity',
2759+
'flood-color',
2760+
'flood-opacity',
2761+
'lighting-color',
2762+
2763+
'marker',
2764+
'marker-end',
2765+
'marker-mid',
2766+
'marker-start',
2767+
2768+
'clip-path',
2769+
'clip-rule',
2770+
'mask',
2771+
'mask-type',
2772+
2773+
'cx',
2774+
'cy',
2775+
'r',
2776+
'rx',
2777+
'ry',
2778+
'x',
2779+
'y',
2780+
'd',
2781+
2782+
'alignment-baseline',
2783+
'baseline-shift',
2784+
'dominant-baseline',
2785+
'glyph-orientation-horizontal',
2786+
'glyph-orientation-vertical',
2787+
'text-anchor',
2788+
'unicode-bidi',
2789+
'word-spacing',
2790+
2791+
'font-size-adjust',
2792+
'font-stretch',
2793+
2794+
'color-rendering',
2795+
'image-rendering',
2796+
'shape-rendering',
2797+
'text-rendering',
2798+
'vector-effect',
2799+
2800+
'transform',
2801+
'transform-origin',
2802+
2803+
'pointer-events',
2804+
'visibility',
2805+
27402806
// Custom CSS properties.
27412807
'--*',
27422808
)

tests/phpunit/tests/kses.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ public function test_wp_kses_attr_no_attributes_allowed_with_false() {
10001000
* @ticket 58551
10011001
* @ticket 60132
10021002
* @ticket 64414
1003+
* @ticket 65457
10031004
*
10041005
* @dataProvider data_safecss_filter_attr
10051006
*
@@ -1473,6 +1474,43 @@ public function data_safecss_filter_attr() {
14731474
'css' => 'display: grid',
14741475
'expected' => 'display: grid',
14751476
),
1477+
// SVG presentation attributes introduced in 7.1.0.
1478+
array(
1479+
'css' => 'fill: none',
1480+
'expected' => 'fill: none',
1481+
),
1482+
array(
1483+
'css' => 'fill-rule: evenodd',
1484+
'expected' => 'fill-rule: evenodd',
1485+
),
1486+
array(
1487+
'css' => 'stroke: red',
1488+
'expected' => 'stroke: red',
1489+
),
1490+
array(
1491+
'css' => 'stroke-width: 2',
1492+
'expected' => 'stroke-width: 2',
1493+
),
1494+
array(
1495+
'css' => 'stroke-linecap: round',
1496+
'expected' => 'stroke-linecap: round',
1497+
),
1498+
array(
1499+
'css' => 'paint-order: stroke',
1500+
'expected' => 'paint-order: stroke',
1501+
),
1502+
array(
1503+
'css' => 'vector-effect: non-scaling-stroke',
1504+
'expected' => 'vector-effect: non-scaling-stroke',
1505+
),
1506+
array(
1507+
'css' => 'clip-rule: evenodd',
1508+
'expected' => 'clip-rule: evenodd',
1509+
),
1510+
array(
1511+
'css' => 'text-anchor: middle',
1512+
'expected' => 'text-anchor: middle',
1513+
),
14761514
);
14771515
}
14781516

0 commit comments

Comments
 (0)