Icons Registry: Allow digits and underscores in icon slugs#79623
Conversation
…derscores Update the icon name validation to accept slugs that start with a digit (e.g. "500px") and that contain underscores. The first character is now allowed to be a lowercase letter or digit, and the remaining characters may include lowercase letters, digits, hyphens, and underscores. Expand the test data providers to cover the newly accepted names and the positional invalid cases (leading hyphen/underscore, uppercase, non-string name types). Co-Authored-By: Claude <noreply@anthropic.com>
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
mcsf
left a comment
There was a problem hiding this comment.
Looks good, but would like to know whether it was intentional to allow trailing hyphens/underscores. :)
| 'underscore at the end' => array( 'test-collection/my-icon_' ), | ||
| 'hyphen at the end' => array( 'test-collection/my-icon-' ), |
|
Flaky tests detected in 6736ae2. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/28360379171
|
Icon names should read as clean slugs, so a trailing hyphen or underscore should not be permitted even though the previous pattern allowed it. Require names to both start and end with a lowercase letter or digit. Co-Authored-By: Claude <noreply@anthropic.com>
|
Thank you @t-hamano! |
Follow-up to #77260
What?
Relax the icon slug validation in the Icons Registry to allow:
html5,500px,w3c).my_icon).Why?
The current validation is too strict for real-world icon sets. Many widely used icons contain digits, such as
html5,500px, andw3c. Some consumers also want to use underscores in addition to hyphens.How?
Update the validation regex, allowing the first character to be a lowercase letter or digit and the rest to include lowercase letters, digits, hyphens, and underscores. Unit tests have also been updated to thoroughly test these new rules.
Testing Instructions
Run the icon registry unit tests:
npm run test:unit:php:base -- --filter 'WP_Test_Icons_Registry_Gutenberg'Use of AI Tools
This PR was authored with the assistance of Claude Code, reviewed and verified by the contributor.