-
Notifications
You must be signed in to change notification settings - Fork 832
Description
Problem :
I found that the IP regex pattern /\b((\d{1,3}\.){3}\d{1,3})\b|\b([a-fA-F0-9:]+:+[a-fA-F0-9:]+)\b/g
at Source
will fails to handle several edge cases and may incorrectly validate certain IP formats.
Propsal :
Proposed pattern: /\s*(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\s*|\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*/g
These are the key differences between previous regex and proposed regex
Key Differences Between Current Regex and Proposed Regex
# | Feature | Current Regex | Proposed Regex |
---|---|---|---|
1 | IPv4 Range Validation | \d{1,3} → Accepts 0-999 |
`25[0-5] |
2a | Invalid IPv4: 999.999.999.999 | ✅ Matches (Wrong Match) | ❌ Rejects (Correct - All octets way beyond 255 is invalid) |
2b | Invalid IPv4: 256.256.256.256 | ✅ Matches (Wrong Match) | ❌ Rejects (Correct - Max is 255) |
2c | Invalid IPv4: 1.2.3 | ✅ Matches (Wrong Match) | ❌ Rejects (Correct - IPv4 requires exactly 4 octets) |
3 | Boundary Detection | \b word boundaries |
\s* whitespace |
4 | Pattern Length | ~50 characters | ~2000 characters |
5 | IPv6 Validation | [a-fA-F0-9:]+:+[a-fA-F0-9:]+ → Very loose |
Comprehensive patterns → Strict |
6 | False Positives: abc:def | ✅ Matches (BAD) | ❌ Rejects (GOOD) |
Goal
Enhance the IP validation to ensure correctly validate certain addresses
Assign to Me
I would like to work on this issue.
Kindly assign this issue to me so that I can proceed with implementing and testing the improved regex validation.