Potential fix for code scanning alert no. 13: Inefficient regular expression #1614
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/reactplay/react-play/security/code-scanning/13
The inefficient regular expression should be rewritten to avoid ambiguity in the repetition. The most problematic part is
[0-9]+inside a repeated group followed by an optional operator. This can be refactored so that each "term" is clearly defined: a sequence of digits, possibly with decimal points, followed by an operator. We can change this to:(?:[0-9]+[-+*/])*[0-9]*, or even better, use a non-greedy form to prevent ambiguity, or ensure the "operator" always follows a number, preventing ambiguous matches. A common pattern for simple calculator expressions is([0-9]+(\.[0-9]+)?([-+*/][0-9]+(\.[0-9]+)?]*)?), but to minimize disruption and preserve original logic, use/^(?:[0-9]+[-+*/])*[0-9]*$/.Steps:
/^(?:[0-9]+[-+*/]?)*[0-9]*$/with/^(?:[0-9]+[-+*/])*[0-9]*$/. This removes the ambiguity by ensuring the operator is always present between numbers, matching sequences like12+34*56.Suggested fixes powered by Copilot Autofix. Review carefully before merging.