Skip to content

Commit dc00d71

Browse files
committed
Change regular expressions for email validation
Note that it does not work for all email addresses according to the standard.
1 parent 182a0a0 commit dc00d71

5 files changed

Lines changed: 9 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [0.3.1] - 2017-08-03
8+
### Fixed
9+
- Regular expressions for validating email addresses.
10+
711
## [0.3] - 2017-03-24
812
### Added
913
- Specification can now specify multiple endpoints.

apimas-drf/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
apimas-drf 0.3
1+
apimas-drf 0.3.1

apimas/apimas/cli/custom_types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
class Email(StringParamType):
1010
name = 'email'
1111

12-
# http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/
13-
regex = re.compile(r"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
14-
r"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
15-
r"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$")
12+
regex = re.compile(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)")
1613

1714
def convert(self, value, param, ctx):
1815
value = super(Email, self).convert(value, param, ctx)

apimas/apimas/clients/extensions.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import random
22
import re
3-
from collections import Iterable
43
from datetime import datetime, date
54
from cerberus import Validator
65
from requests.compat import urljoin
@@ -70,8 +69,6 @@ def _validate_type_file(self, value):
7069
def _validate_type_email(self, value):
7170
if not isinstance(value, (str, unicode)):
7271
return False
73-
# http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/
74-
regex = re.compile(r"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
75-
r"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
76-
r"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$")
72+
regex = re.compile(
73+
r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)")
7774
return bool(regex.match(value))

apimas/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
apimas 0.3
1+
apimas 0.3.1

0 commit comments

Comments
 (0)