Skip to content

Commit fa3cb28

Browse files
Ni-Knightkvesteri
authored andcommitted
Small change to domain RE (#76)
* Update domain.py Removing [.] from in the regex and added a non capturing group for it. * Update test_domain.py Added the following test case `a......b.com` to invalid domains. * `+` and not a `*` * removed extra `,` * Update test_domain.py removed extra lines.
1 parent d8a5c21 commit fa3cb28

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

tests/test_domain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def test_returns_true_on_valid_domain(value):
2323
'example.',
2424
'-example.com',
2525
'example',
26+
'a......b.com'
2627
])
2728
def test_returns_failed_validation_on_invalid_domain(value):
2829
assert isinstance(domain(value), ValidationFailure)

validators/domain.py

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

55
pattern = re.compile(
6-
r'^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|' # domain pt.1
6+
r'^(:?(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|' # domain pt.1
77
r'([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|' # domain pt.2
8-
r'([a-zA-Z0-9][-_.a-zA-Z0-9]{0,61}[a-zA-Z0-9]))\.' # domain pt.3
8+
r'([a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]))\.)+' # domain pt.3
99
r'([a-zA-Z]{2,13}|(xn--[a-zA-Z0-9]{2,30}))$' # TLD
1010
)
1111

0 commit comments

Comments
 (0)