Opened 13 years ago
Closed 13 years ago
#17483 closed Bug (invalid)
EmailField : valid email address
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Mail) | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
There is an error in regexp "email_re" allocated here
https://code.djangoproject.com/browser/django/trunk/django/core/validators.py#L161
According to this regexp e-mail address in form ipv4 address (SMTP 4.1.3) e.g. user_name@123.123.123.12 is not matched.
Correct regexp :
email_re = re.compile( r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string r')@(((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$)' # domain r'|(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$)', re.IGNORECASE) # literal form, ipv4 address (SMTP 4.1.3)
Attachments (1)
Change History (3)
comment:1 by , 13 years ago
by , 13 years ago
comment:2 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
What authoritative specification are you basing the assertion that user_name@123.123.123.12 should be accepted as valid? Every one I have checked brackets around the address are required. For example from http://www.ietf.org/rfc/rfc2821.txt:
4.1.3 Address Literals Sometimes a host is not known to the domain name system and communication (and, in particular, communication to report and repair the error) is blocked. To bypass this barrier a special literal form of the address is allowed as an alternative to a domain name. For IPv4 addresses, this form uses four small decimal integers separated by dots and enclosed by brackets such as [123.255.37.2], which indicates an (IPv4) Internet Address in sequence-of-octets form.
My reading of the spec is that the brackets are required, thus removing them from the regex would be wrong. The validator is correctly failing to validate user_name@123.123.123.12. The correct way to write that address is user_name@[123.123.123.12], and that is accepted by the Django email validator.
Example