-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support email addresses with international domain names
`colander.Email` uses a regex which does not allow domain names beginning with `xn--` or Unicode characters. Either of these limitations prevents users from registering with email addresses that use international domain names. This commit replaces the validator with an alternate pattern taken from the HTML spec which is used by Chrome and which at least allows the Punycode version of an internationalized email address to be used. I opted not to just allow unicode chars because we first have to make sure that the rest of our stack supports it. Alternatively we could convert to Punycode automatically when deserializing the user's input. Fixes #4662
- Loading branch information
1 parent
25fc3ce
commit 759e0b9
Showing
2 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
|
||
from mock import Mock | ||
|
||
import colander | ||
|
||
from h.validators import Email | ||
|
||
|
||
class TestEmail(object): | ||
@pytest.mark.parametrize('email', [ | ||
'jimsmith@foobar.com', | ||
'international@xn--domain.com', | ||
'jim.smith@gmail.com', | ||
'jim.smith@foo.bar.com', | ||
]) | ||
def test_accepts_valid_addresses(self, schema_node, email): | ||
validator = Email() | ||
validator(schema_node, email) | ||
|
||
@pytest.mark.parametrize('email', [ | ||
' spaces @ spaces.com', | ||
]) | ||
def test_rejects_invalid_addresses(self, schema_node, email): | ||
validator = Email() | ||
|
||
with pytest.raises(colander.Invalid): | ||
validator(schema_node, email) | ||
|
||
@pytest.fixture | ||
def schema_node(self): | ||
""" | ||
Mock for `colander.SchemaNode` arg that validator callables require. | ||
""" | ||
return Mock(spec_set=[]) |