`regexp/use-ignore-case` creates a bug
o-alexandrov opened this issue · comments
Olzhas Alexandrov commented
Information:
- ESLint version: 8.52.0
eslint-plugin-regexp
version: 2.1.1
Description
Rule regexp/use-ignore-case
creates a bug in the following RegExp:
const emailRegex = /.*@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-zA-Z\-\d]+\.)+[a-zA-Z]{2,}))$/
It modifies the RegExp to:
const emailRegex = /.*@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-z\-\d]+\.)+[a-z]{2,}))$/I
So a valid email then is ignored:
example@me.com
Michael Schmidt commented
So a valid email then is ignored:
example@me.com
No, it isn't.
Welcome to Node.js v20.5.1.
Type ".help" for more information.
> /.*@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-zA-Z\-\d]+\.)+[a-zA-Z]{2,}))$/.test("example@me.com")
true
> /.*@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-z\-\d]+\.)+[a-z]{2,}))$/i.test("example@me.com")
true
These 2 regexes are exactly equivalent to each other. So either something went wrong during your testing, or this isn't the whole regex, because use-ignore-case
transformed this particular regex correctly AFAICT.
Olzhas Alexandrov commented
Thank you, you are correct, it's the transformation I do for the function that breaks, due to the addition of the i
flag.