Skip to content

Commit acd8d74

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents 4799c40 + aa8e167 commit acd8d74

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/wp-includes/class-wp-icons-registry.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ public function register( $icon_name, $icon_properties ) {
170170
);
171171
return false;
172172
}
173+
174+
$icon_properties['content'] = $sanitized_icon_content;
173175
}
174176

175177
$qualified_name = $collection . '/' . $unqualified_name;

tests/phpunit/tests/icons/wpIconsRegistry.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,28 @@ public function test_register_icon_with_file_path() {
258258
$this->assertStringContainsString( '<svg', $icon['content'] );
259259
}
260260

261+
/**
262+
* Should register an icon with its `content` sanitized.
263+
*
264+
* @ticket 64847
265+
*
266+
* @covers ::register
267+
*/
268+
public function test_register_icon_sanitizes_content() {
269+
$result = $this->registry->register(
270+
'test-collection/unsafe-content',
271+
array(
272+
'label' => 'Icon',
273+
'content' => '<svg viewbox="0 0 24 24" onload="alert(1)"><path d="M0 0" /></svg>',
274+
)
275+
);
276+
277+
$this->assertTrue( $result );
278+
279+
$icon = $this->registry->get_registered_icon( 'test-collection/unsafe-content' );
280+
$this->assertSame( '<svg viewbox="0 0 24 24"><path d="M0 0" /></svg>', $icon['content'] );
281+
}
282+
261283
/**
262284
* Should fail to register an icon that provides both `content` and `file_path`.
263285
*

0 commit comments

Comments
 (0)