Ticket #229 (closed defect: fixed)
TLD Regex
| Reported by: | arantius-magicpassword@… | Owned by: | t-bone |
|---|---|---|---|
| Priority: | major | Component: | Magic Password Generator |
| Version: | 1.5 | Severity: | Broken |
| Keywords: | Cc: |
Description
I examined the TLD regex in the bookmarklet to find out that it is a bit too simplistic. For ccTLD it will use the same passwords for many sites.
E.g. for www.amazon.co.uk and www.bbc.co.uk the regex /[^.]*\.[^.]*$/ will generate "co.uk".
I would suggest the following regex (not tested):
/[^.]+\.(([^.]{2,3}\.)?[^.]{2}|[^.]{3,})$/
Rational: If it ends with 3 chars or more it is not a ccTLD so the reduction is pretty much the original regex. If it ends with 2 chars it IS a ccTLD. In that case it is highly unlikely that the main domain will be 2-3 chars, so 2-3 chars are assumed to be part of the ccTLD (e.g. com.uk, ac.uk, org.uk, but not google.fr). So, for 2-3 chars we take *.123.uk, and for longer just *.fr like the original regex. We also have to have at least one char in the main domain.