Skip to content

Commit

Permalink
Merge pull request #5414 from mondeja/5367
Browse files Browse the repository at this point in the history
Raise InvalidUrl if host starts with '.' character.
  • Loading branch information
sigmavirus24 committed Dec 29, 2021
2 parents 2b06a95 + 658c10e commit d096599
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requests/models.py
Expand Up @@ -403,7 +403,7 @@ def prepare_url(self, url, params):
host = self._get_idna_encoded_host(host)
except UnicodeError:
raise InvalidURL('URL has an invalid label.')
elif host.startswith(u'*'):
elif host.startswith((u'*', u'.')):
raise InvalidURL('URL has an invalid label.')

# Carefully reconstruct the network location
Expand Down
2 changes: 2 additions & 0 deletions tests/test_requests.py
Expand Up @@ -81,6 +81,8 @@ def test_entry_points(self):
(InvalidSchema, 'localhost.localdomain:3128/'),
(InvalidSchema, '10.122.1.1:3128/'),
(InvalidURL, 'http://'),
(InvalidURL, 'http://*example.com'),
(InvalidURL, 'http://.example.com'),
))
def test_invalid_url(self, exception, url):
with pytest.raises(exception):
Expand Down

0 comments on commit d096599

Please sign in to comment.