Skip to content

Commit

Permalink
Change regular expressions for email validation
Browse files Browse the repository at this point in the history
Note that it does not work for all email addresses according to the
standard.
  • Loading branch information
theosotr committed Aug 3, 2017
1 parent 182a0a0 commit dc00d71
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.3.1] - 2017-08-03
### Fixed
- Regular expressions for validating email addresses.

## [0.3] - 2017-03-24
### Added
- Specification can now specify multiple endpoints.
Expand Down
2 changes: 1 addition & 1 deletion apimas-drf/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
apimas-drf 0.3
apimas-drf 0.3.1
5 changes: 1 addition & 4 deletions apimas/apimas/cli/custom_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
class Email(StringParamType):
name = 'email'

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

def convert(self, value, param, ctx):
value = super(Email, self).convert(value, param, ctx)
Expand Down
7 changes: 2 additions & 5 deletions apimas/apimas/clients/extensions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import random
import re
from collections import Iterable
from datetime import datetime, date
from cerberus import Validator
from requests.compat import urljoin
Expand Down Expand Up @@ -70,8 +69,6 @@ def _validate_type_file(self, value):
def _validate_type_email(self, value):
if not isinstance(value, (str, unicode)):
return False
# http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/
regex = re.compile(r"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
r"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
r"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$")
regex = re.compile(
r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)")
return bool(regex.match(value))
2 changes: 1 addition & 1 deletion apimas/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
apimas 0.3
apimas 0.3.1

0 comments on commit dc00d71

Please sign in to comment.