File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -394,6 +394,8 @@ def _merge_url(self, url: URL | str) -> URL:
394394 to create the URL used for the outgoing request.
395395 """
396396 merge_url = URL (url )
397+ if merge_url .scheme and not merge_url .host :
398+ raise InvalidURL (f"Invalid URL '{ url } ': has scheme but missing host" )
397399 if merge_url .is_relative_url :
398400 # To merge URLs we always append to the base URL. To get this
399401 # behaviour correct we always ensure the base URL ends in a '/'
Original file line number Diff line number Diff line change @@ -44,6 +44,21 @@ def test_get_invalid_url(server, url):
4444 client .get (url )
4545
4646
47+ def test_get_invalid_url_with_scheme_no_host ():
48+ """
49+ Regression test for: https://github.com/encode/httpx/issues/1832
50+ URLs with scheme but no host should raise InvalidURL.
51+ """
52+ with httpx .Client () as client :
53+ with pytest .raises (httpx .InvalidURL ) as exc :
54+ client .get ("https:/google.com" )
55+ assert "has scheme but missing host" in str (exc .value )
56+
57+ with pytest .raises (httpx .InvalidURL ) as exc :
58+ client .get ("https:///google.com" )
59+ assert "has scheme but missing host" in str (exc .value )
60+
61+
4762def test_build_request (server ):
4863 url = server .url .copy_with (path = "/echo_headers" )
4964 headers = {"Custom-header" : "value" }
You can’t perform that action at this time.
0 commit comments