Skip to content
Closed
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
19 changes: 19 additions & 0 deletions src/wp-includes/class-wp-icons-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,25 @@ protected function sanitize_icon_content( $icon_content ) {
'transform' => true,
'focusable' => true,
),
'rect' => array(
'fill' => true,
'fill-rule' => true,
'x' => true,
'y' => true,
'width' => true,
'height' => true,
'rx' => true,
'ry' => true,
'transform' => true,
),
'circle' => array(
'fill' => true,
'fill-rule' => true,
'cx' => true,
'cy' => true,
'r' => true,
'transform' => true,
),
);
return wp_kses( $icon_content, $allowed_tags );
}
Expand Down
45 changes: 45 additions & 0 deletions tests/phpunit/tests/icons/wpIconsRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,49 @@ public function test_get_content_returns_null_for_invalid_file( $contents, $exte

$this->assertNull( $icon['content'] );
}

/**
* Data provider.
*
* @return array[]
*/
public function data_register_icon_preserves_rect_and_circle() {
return array(
'rect' => array( '<rect fill="currentColor" fill-rule="evenodd" x="4" y="5" width="16" height="14" rx="2" ry="2" transform="rotate(45)" />' ),
'circle' => array( '<circle fill="currentColor" fill-rule="evenodd" cx="12" cy="12" r="3" transform="rotate(45)" />' ),
);
}

/**
* Should preserve the `rect` and `circle` elements that library icons are drawn with.
*
* @ticket 66112
*
* @dataProvider data_register_icon_preserves_rect_and_circle
*
* @covers ::register
*
* @param string $shape Shape element the icon is drawn with.
*/
public function test_register_icon_preserves_rect_and_circle( $shape ) {
$name = 'test-collection/shape-icon';

$this->assertTrue(
$this->registry->register(
$name,
array(
'label' => 'Shape Icon',
'content' => '<svg viewbox="0 0 24 24">' . $shape . '</svg>',
)
)
);

$icon = $this->registry->get_registered_icon( $name );

$this->assertStringContainsString(
$shape,
$icon['content'],
'Attributes were altered or stripped from the shape element.'
);
}
}
Loading