Skip to content

Commit d096599

Browse files
authored
Merge pull request #5414 from mondeja/5367
Raise InvalidUrl if host starts with '.' character.
2 parents 2b06a95 + 658c10e commit d096599

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

requests/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def prepare_url(self, url, params):
403403
host = self._get_idna_encoded_host(host)
404404
except UnicodeError:
405405
raise InvalidURL('URL has an invalid label.')
406-
elif host.startswith(u'*'):
406+
elif host.startswith((u'*', u'.')):
407407
raise InvalidURL('URL has an invalid label.')
408408

409409
# Carefully reconstruct the network location

tests/test_requests.py

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def test_entry_points(self):
8181
(InvalidSchema, 'localhost.localdomain:3128/'),
8282
(InvalidSchema, '10.122.1.1:3128/'),
8383
(InvalidURL, 'http://'),
84+
(InvalidURL, 'http://*example.com'),
85+
(InvalidURL, 'http://.example.com'),
8486
))
8587
def test_invalid_url(self, exception, url):
8688
with pytest.raises(exception):

0 commit comments

Comments
 (0)