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

Optimizer creates unsafe Regex? #236

Open
Uzlopak opened this issue Nov 19, 2021 · 1 comment
Open

Optimizer creates unsafe Regex? #236

Uzlopak opened this issue Nov 19, 2021 · 1 comment

Comments

@Uzlopak
Copy link

Uzlopak commented Nov 19, 2021

Example:
/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){2}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/i
is optimized to

/^(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|[1-9])\.(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){2}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/i

The first is considered a safe regex by safe-regex, the second one not.

@DmitrySoshnikov
Copy link
Owner

Hi @Uzlopak, thanks for reporting. I'm curious which specific part is considered unsafe here? First we need to check if a valid regexp is generated as part of the optimizer, and then see the unsafe part and how we can transform it better. I'll appreciate a PR for this issue.

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

No branches or pull requests

2 participants