Skip to content

Icons Registry: Allow digits and underscores in icon slugs#79623

Merged
t-hamano merged 3 commits into
trunkfrom
fix/icons-registry-allow-digit-underscore-slugs
Jun 29, 2026
Merged

Icons Registry: Allow digits and underscores in icon slugs#79623
t-hamano merged 3 commits into
trunkfrom
fix/icons-registry-allow-digit-underscore-slugs

Conversation

@t-hamano

@t-hamano t-hamano commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #77260

What?

Relax the icon slug validation in the Icons Registry to allow:

  1. Digits in any position (e.g. html5, 500px, w3c).
  2. Underscores anywhere except the first character (e.g. my_icon).

Why?

The current validation is too strict for real-world icon sets. Many widely used icons contain digits, such as html5, 500px, and w3c. 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.

…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>
@t-hamano t-hamano requested review from Mamaduka, mcsf and tyxla June 29, 2026 08:56
@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Feature] Icons Related to Icon registration API and Icon REST API labels Jun 29, 2026
@t-hamano t-hamano marked this pull request as ready for review June 29, 2026 08:58
@t-hamano t-hamano requested a review from spacedmonkey as a code owner June 29, 2026 08:58
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown

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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: mcsf <mcsf@git.wordpress.org>

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

@t-hamano t-hamano added the No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core label Jun 29, 2026

@mcsf mcsf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, but would like to know whether it was intentional to allow trailing hyphens/underscores. :)

Comment on lines +113 to +114
'underscore at the end' => array( 'test-collection/my-icon_' ),
'hyphen at the end' => array( 'test-collection/my-icon-' ),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we want these two?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 951c4f1

@github-actions

Copy link
Copy Markdown

Flaky tests detected in 6736ae2.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/28360379171
📝 Reported issues:

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>

@mcsf mcsf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🙏

@t-hamano t-hamano merged commit 1b7b125 into trunk Jun 29, 2026
43 of 44 checks passed
@t-hamano t-hamano deleted the fix/icons-registry-allow-digit-underscore-slugs branch June 29, 2026 11:07
@github-actions github-actions Bot added this to the Gutenberg 23.6 milestone Jun 29, 2026
@tyxla

tyxla commented Jun 29, 2026

Copy link
Copy Markdown
Member

Thank you @t-hamano!

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

Labels

[Feature] Icons Related to Icon registration API and Icon REST API No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants