Merge pull request #5414 from mondeja/5367

Raise InvalidUrl if host starts with '.' character.
This commit is contained in:
Ian Stapleton Cordasco
2021-12-28 19:39:36 -06:00
committed by GitHub
2 changed files with 3 additions and 1 deletions
+1 -1
View File
@@ -403,7 +403,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
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
+2
View File
@@ -81,6 +81,8 @@ class TestRequests:
(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):