Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Control crashes with certain units #52210

Closed
TimothyBJacobs opened this issue Jul 2, 2023 · 0 comments · Fixed by #52211
Closed

Unit Control crashes with certain units #52210

TimothyBJacobs opened this issue Jul 2, 2023 · 0 comments · Fixed by #52211
Assignees
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended

Comments

@TimothyBJacobs
Copy link
Member

TimothyBJacobs commented Jul 2, 2023

Description

The <UnitControl> component does not escape the units used to build the firstCharacters regular expression, see

return [ list, new RegExp( `^(?:${ firstCharacters })$`, 'i' ) ];

This causes the component to crash with RegExp syntax errors like Nothing to repeat when units are used that contain regex control characters.

There is a escapeRegExp helper that I think could be applied to the first character value.

This looks to be a bug introduced in #39303.

Step-by-step reproduction instructions

  1. Use the UnitControl in a block or any React environment with the following code.
<UnitControl
	value={value}
	onChange={onChange}
	units={[
		{
			label: '+',
			value: '+',
		},
		{
			label: '-',
			value: '-',
		},
	]}
/>

Screenshots, screen recording, code snippet

No response

Environment info

  • Gutenberg 16.1
  • Firefox

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@TimothyBJacobs TimothyBJacobs added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Jul 2, 2023
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Jul 2, 2023
@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants