Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backport-changelog/7.1/12623.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/12623

* https://github.com/WordPress/gutenberg/pull/80508
2 changes: 2 additions & 0 deletions lib/class-wp-icons-registry-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public function register( $icon_name, $icon_properties ) {
);
return false;
}

$icon_properties['content'] = $sanitized_icon_content;
}

$qualified_name = $collection . '/' . $unqualified_name;
Expand Down
2 changes: 2 additions & 0 deletions lib/compat/wordpress-7.0/class-wp-icons-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ protected function register( $icon_name, $icon_properties ) {
);
return false;
}

$icon_properties['content'] = $sanitized_icon_content;
}

$icon = array_merge(
Expand Down
17 changes: 17 additions & 0 deletions phpunit/class-wp-icons-registry-gutenberg-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,23 @@ public function test_register_icon_with_file_path() {
$this->assertStringContainsString( '<svg', $registered_icons[0]['content'] );
}

/**
* Should register an icon with its `content` sanitized.
*/
public function test_register_icon_sanitizes_content() {
$name = 'test-collection/unsafe-content';
$settings = array(
'label' => 'Icon',
'content' => '<svg viewbox="0 0 24 24" onload="alert(1)"><path d="M0 0" /></svg>',
);

$result = $this->register( $name, $settings );
$this->assertTrue( $result );

$icon = $this->registry->get_registered_icon( $name );
$this->assertSame( '<svg viewbox="0 0 24 24"><path d="M0 0" /></svg>', $icon['content'] );
}

/**
* Should fail to register an icon that provides both `content` and `file_path`.
*
Expand Down
Loading