Skip to content

Commit 3e51bae

Browse files
committed
Add support for IDN validation, refs #14
1 parent 46426b8 commit 3e51bae

4 files changed

Lines changed: 35 additions & 11 deletions

File tree

‎CHANGES.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ Changelog
22
---------
33

44

5+
0.10.0 (2016-01-09)
6+
^^^^^^^^^^^^^^^^^^^
7+
8+
- Added support for internationalized domain names in ``domain`` validator
9+
10+
511
0.9.0 (2015-10-10)
612
^^^^^^^^^^^^^^^^^^
713

‎tests/test_domain.py‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
from validators import domain, ValidationFailure
55

66

7-
@pytest.mark.parametrize(('value',), [
8-
('example.com',),
7+
@pytest.mark.parametrize('value', [
8+
'example.com',
9+
'xn----gtbspbbmkef.xn--p1ai',
10+
'underscore_subdomain.example.com',
11+
'something.versicherung'
912
])
1013
def test_returns_true_on_valid_domain(value):
1114
assert domain(value)
1215

1316

14-
@pytest.mark.parametrize(('value',), [
15-
('example.com/',),
16-
('example.com:4444',),
17-
('example.-com',),
18-
('example.',),
19-
('example',),
17+
@pytest.mark.parametrize('value', [
18+
'example.com/',
19+
'example.com:4444',
20+
'example.-com',
21+
'example.',
22+
'-example.com',
23+
'example',
2024
])
2125
def test_returns_failed_validation_on_invalid_domain(value):
2226
assert isinstance(domain(value), ValidationFailure)

‎validators/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
from .utils import ValidationFailure, validator # noqa
1414
from .uuid import uuid # noqa
1515

16-
__version__ = '0.9'
16+
__version__ = '0.10'

‎validators/domain.py‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from .utils import validator
44

55
pattern = re.compile(
6-
r'^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.)'
7-
r'{1,126}(?!\d+)[a-zA-Z\d]{1,63}$'
6+
r'^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|'
7+
r'([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|'
8+
r'([a-zA-Z0-9][-_.a-zA-Z0-9]{1,61}[a-zA-Z0-9]))\.'
9+
r'([a-zA-Z]{2,13}|[a-zA-Z0-9-]{2,30}.[a-zA-Z]{2,3})$'
810
)
911

1012

@@ -24,6 +26,18 @@ def domain(value):
2426
>>> domain('example.com/')
2527
ValidationFailure(func=domain, ...)
2628
29+
30+
Supports IDN domains as well::
31+
32+
>>> domain('xn----gtbspbbmkef.xn--p1ai')
33+
True
34+
35+
.. versionadded:: 0.9
36+
37+
.. versionchanged:: 0.10
38+
39+
Added support for internationalized domain name (IDN) validation.
40+
2741
:param value: domain string to validate
2842
"""
2943
return pattern.match(value)

0 commit comments

Comments
 (0)