Skip to content

Commit 744628d

Browse files
committed
Fix public url validation, refs #29
1 parent c6735b4 commit 744628d

3 files changed

Lines changed: 5 additions & 8 deletions

File tree

‎tests/test_url.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def test_returns_failed_validation_on_invalid_url(address):
122122
(u'http://username:password@192.168.10.10:4010/', True),
123123
(u'http://10.0.10.1', True),
124124
(u'http://127.0.0.1', True),
125+
(u'foo://127.0.0.1', True),
125126
(u'http://username:password@127.0.0.1:8080', True),
126127
127128
])

‎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.10.3'
16+
__version__ = '0.10.4'

‎validators/url.py‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,8 @@ def url(value, public=False):
8787
:param value: URL address string to validate
8888
:param public: (default=False) Set True to only allow a public IP address
8989
"""
90+
result = pattern.match(value)
9091
if not public:
91-
return pattern.match(value)
92+
return result
9293

93-
match_result = pattern.match(value)
94-
95-
if match_result.groupdict()['private_ip']:
96-
return False
97-
98-
return match_result
94+
return result and not result.groupdict()['private_ip']

0 commit comments

Comments
 (0)