Skip to content

Icons: Enforce strict name validation in register method#11245

Open
im3dabasia wants to merge 5 commits intoWordPress:trunkfrom
im3dabasia:try/add-register-name-validation
Open

Icons: Enforce strict name validation in register method#11245
im3dabasia wants to merge 5 commits intoWordPress:trunkfrom
im3dabasia:try/add-register-name-validation

Conversation

@im3dabasia
Copy link

@im3dabasia im3dabasia commented Mar 13, 2026

Trac ticket: https://core.trac.wordpress.org/ticket/64847

Use of AI Tools

Copilot

Caution

Commit this PR after the wp/7.0 release branch has been created. This PR targets the 7.1 release.

@github-actions
Copy link

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' ),
	);
}

@im3dabasia
Copy link
Author

Thanks for the continuous iterations on this PR. I have addressed the feedbacks in this commit bf30902

@im3dabasia im3dabasia requested a review from t-hamano March 17, 2026 05:25
@im3dabasia im3dabasia marked this pull request as ready for review March 17, 2026 05:26
@github-actions
Copy link

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props im3dabasia1, wildworks.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Additionally, it would be great if you made the same changes to WordPress/gutenberg#76079.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants