regexp-tree icon indicating copy to clipboard operation
regexp-tree copied to clipboard

Optimizer creates unsafe Regex?

Open Uzlopak opened this issue 3 years ago • 1 comments

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.

Uzlopak avatar Nov 19 '21 21:11 Uzlopak

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.

DmitrySoshnikov avatar Nov 20 '21 03:11 DmitrySoshnikov