Skip to content

Commit

Permalink
Merge pull request #6644 from sigmavirus24/bug/6643
Browse files Browse the repository at this point in the history
Trim excess leading path separators
  • Loading branch information
sigmavirus24 authored Feb 23, 2024
2 parents 382fc2c + 60389df commit 3587a5f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/requests/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ def request_url(self, request, proxies):
using_socks_proxy = proxy_scheme.startswith("socks")

url = request.path_url
if url.startswith("//"): # Don't confuse urllib3
url = f"/{url.lstrip('/')}"

if is_proxied_http_request and not using_socks_proxy:
url = urldefragauth(request.url)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_adapters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import requests.adapters


def test_request_url_trims_leading_path_separators():
"""See also https://github.com/psf/requests/issues/6643."""
a = requests.adapters.HTTPAdapter()
p = requests.Request(method="GET", url="http://127.0.0.1:10000//v:h").prepare()
assert "/v:h" == a.request_url(p, {})

0 comments on commit 3587a5f

Please sign in to comment.