One function

email in python-validators/validators

The author described this change as Fix email regex issue 140 (#411). It counts as a record because the check below fails on the code as it stood at 9dac863b4 and passes on 25fcef05c, with nothing else changed between the two runs.

Fix saved2025-03-28
Sharing licenceMIT · LICENSE.txt
Change size+7 3

What the code was meant to do, written into the code itself as a docstring

Validate an email address. This was inspired from [Django's email validator][1]. Also ref: [RFC 1034][2], [RFC 5321][3] and [RFC 5322][4]. [1]: https://github.com/django/django/blob/main/django/core/validators.py#L174 [2]: https://www.rfc-editor.org/rfc/rfc1034 [3]: https://www.rfc-editor.org/rfc/rfc5321 [4]: https://www.rfc-editor.org/rfc/rfc5322 Examples: Args: value: eMail string to validate. ipv6_address: When the domain part is an IPv6 address. ipv4_address: When the domain part is an IPv4 address. simple_host: When the domain part is a simple hostname. rfc_1034: Allow trailing dot in domain name. Ref: [RFC 1034](https://www.rfc-editor.org/rfc/rfc1034). rfc_2782: Domain name is of type service record. Ref: [RFC 2782](https://www.rfc-editor.org/rfc/rfc2782). Returns: (Literal[True]): If `value` is a valid eMail. (ValidationError): If `value` is an invalid eMail.

The change

7474 )
7575 if re.match(
7676 # extended latin
77- r"(^[\u0100-\u017F\u0180-\u024F]"
77+ r"(^[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF]"
7878 # dot-atom
79- + r"|[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$"
79+ + r"|[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF0-9a-z!#$%&'*+/=?^_`{}|~\-]+"
80+ + r"(\.[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF0-9a-z!#$%&'*+/=?^_`{}|~\-]+)*$"
8081 # quoted-string
81- + r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\011.])*"$)',
82+ + r'|^"('
83+ + r"[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF\001-\010\013\014\016-\037"
84+ + r"!#-\[\]-\177]|\\[\011.]"
85+ + r')*")$',
8286 username_part,
8387 re.IGNORECASE,
8488 )

The check that tells the two apart

failpass·tests/test_email.py::test_returns_failed_validation_on_invalid_email[stephen

Check file tests/test_email.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it9dac863b452253f3ae1b7fd3370e509c52c46b85
Broken version dated2025-03-28
Modulevalidators.email
Units changedemail
Fingerprint8d98f61c510a8ae9
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in python-validators/validators