Icons: Enforce strict name validation in register method#11245
Icons: Enforce strict name validation in register method#11245im3dabasia wants to merge 5 commits intoWordPress:trunkfrom
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for the PR! I think there are roughly two areas for improvement.
public function test() {
$result = $this->register( 'invalid-name', array() );
$this->assertFalse( $result );
}This test appears correct at first glance, but note that the second argument is an empty array. If the second argument is empty, it will cause an error here. In other words, this test does not guarantee whether the error is caused by an invalid icon name.
Another suggestion is to use a data provider, which reduces the amount of code and allows us to cover more cases. For example:
public function test_invalid_icon_names( $icon_name ) {
$settings = array(
'label' => 'Icon',
'content' => '<svg></svg>',
);
$result = $this->register( $icon_name, $settings );
$this->assertFalse( $result );
}
public function data_invalid_icon_names() {
return array(
'non-string name' => array( 1 ),
'no namespace' => array( 'plus' ),
'uppercase characters' => array( 'Core/Plus' ),
'invalid characters' => array( 'test/_doing_it_wrong' ),
);
}|
Thanks for the continuous iterations on this PR. I have addressed the feedbacks in this commit bf30902 |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
t-hamano
left a comment
There was a problem hiding this comment.
LGTM!
Additionally, it would be great if you made the same changes to WordPress/gutenberg#76079.
Trac ticket: https://core.trac.wordpress.org/ticket/64847
Use of AI Tools
Copilot
Caution
Commit this PR after the
wp/7.0release branch has been created. This PR targets the 7.1 release.