safe-regex icon indicating copy to clipboard operation
safe-regex copied to clipboard

Optimized regex is deemed unsafe

Open Uzlopak opened this issue 4 years ago • 0 comments

Hi @davisjam

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 by regexp-tree 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.

Is this a valid finding? I just want to determine if this an issue of regexp-tree or safe-regex as I recommend, that the eslint plugin optimize-regex should check optimized regexes through safe-regex to ensure that optimized regexes dont open another can of worms.

https://github.com/DmitrySoshnikov/regexp-tree/issues/236 https://github.com/BrainMaestro/eslint-plugin-optimize-regex/issues/75

Uzlopak avatar Nov 19 '21 21:11 Uzlopak