@@ -74,6 +74,20 @@ private function create_temp_icon_file( $contents, $extension = 'svg' ) {
7474 return $ this ->temp_file ;
7575 }
7676
77+ /**
78+ * Invokes the WP_Icons_Registry::sanitize_icon_content method on the registry instance.
79+ *
80+ * @param string $icon_content The icon SVG content to sanitize.
81+ * @return string The sanitized icon SVG content.
82+ */
83+ private function sanitize_icon_content ( $ icon_content ) {
84+ $ method = new ReflectionMethod ( $ this ->registry , 'sanitize_icon_content ' );
85+ if ( PHP_VERSION_ID < 80100 ) {
86+ $ method ->setAccessible ( true );
87+ }
88+ return $ method ->invoke ( $ this ->registry , $ icon_content );
89+ }
90+
7791 /**
7892 * Provides valid namespaced icon names, including names that contain,
7993 * start or end with digits, as well as underscores and hyphens.
@@ -284,6 +298,58 @@ public function test_register_icon_sanitizes_content() {
284298 $ this ->assertSame ( '<svg viewbox="0 0 24 24"><path d="M0 0" /></svg> ' , $ icon ['content ' ] );
285299 }
286300
301+ /**
302+ * @ticket 65795
303+ *
304+ * @covers ::sanitize_icon_content
305+ *
306+ * @dataProvider data_sanitize_icon_content
307+ *
308+ * @param string $input The icon content to sanitize.
309+ * @param string $expected The expected sanitized output.
310+ */
311+ public function test_sanitize_icon_content ( $ input , $ expected ) {
312+ $ this ->assertSame ( $ expected , $ this ->sanitize_icon_content ( $ input ) );
313+ }
314+
315+ /**
316+ * Data provider for test_sanitize_icon_content.
317+ *
318+ * @return array<string, array{0: string, 1: string}> Data sets of [ $input, $expected ].
319+ */
320+ public function data_sanitize_icon_content () {
321+ return array (
322+ 'allows fill and clip rules on svg ' => array (
323+ '<svg fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"><path d="M0 0" /></svg> ' ,
324+ '<svg fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"><path d="M0 0" /></svg> ' ,
325+ ),
326+ 'allows stroke attributes and style on svg ' => array (
327+ '<svg style="fill: none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" vector-effect="non-scaling-stroke"><path d="M0 0" /></svg> ' ,
328+ '<svg style="fill: none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" vector-effect="non-scaling-stroke"><path d="M0 0" /></svg> ' ,
329+ ),
330+ 'allows clip rule, opacity and stroke on path ' => array (
331+ '<svg><path d="M0 0" fill-rule="evenodd" clip-rule="evenodd" opacity="0.4" style="fill: none" stroke="currentColor" vector-effect="non-scaling-stroke" /></svg> ' ,
332+ '<svg><path d="M0 0" fill-rule="evenodd" clip-rule="evenodd" opacity="0.4" style="fill: none" stroke="currentColor" vector-effect="non-scaling-stroke" /></svg> ' ,
333+ ),
334+ 'allows clip rule and stroke on polygon ' => array (
335+ '<svg><polygon points="0,0 1,1" clip-rule="evenodd" stroke="currentColor" vector-effect="non-scaling-stroke" /></svg> ' ,
336+ '<svg><polygon points="0,0 1,1" clip-rule="evenodd" stroke="currentColor" vector-effect="non-scaling-stroke" /></svg> ' ,
337+ ),
338+ 'allows rect ' => array (
339+ '<svg><rect x="4" y="5" width="16" height="14" rx="2" ry="2" fill="currentColor" stroke="currentColor" transform="rotate(45)" vector-effect="non-scaling-stroke" /></svg> ' ,
340+ '<svg><rect x="4" y="5" width="16" height="14" rx="2" ry="2" fill="currentColor" stroke="currentColor" transform="rotate(45)" vector-effect="non-scaling-stroke" /></svg> ' ,
341+ ),
342+ 'allows circle ' => array (
343+ '<svg><circle cx="12" cy="12" r="3" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" transform="rotate(45)" vector-effect="non-scaling-stroke" /></svg> ' ,
344+ '<svg><circle cx="12" cy="12" r="3" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" transform="rotate(45)" vector-effect="non-scaling-stroke" /></svg> ' ,
345+ ),
346+ 'strips opacity on elements other than path ' => array (
347+ '<svg opacity="0.4"><rect width="1" height="1" opacity="0.4" /></svg> ' ,
348+ '<svg><rect width="1" height="1" /></svg> ' ,
349+ ),
350+ );
351+ }
352+
287353 /**
288354 * Should fail to register an icon that provides both `content` and `file_path`.
289355 *
0 commit comments