Skip to content
Myr

Trim excess leading path separators

Before adoption: this commit came in with the history the project adopted, so no landing records it.

A URL with excess leading / (path-separator)s would cause urllib3 to attempt to reparse the request-uri as a full URI with a host and port. This bypasses that logic in ConnectionPool.urlopen by replacing these leading /s with just a single /. Closes #6643

authored by Ian Stapleton Cordasco · committed by Ian Stapleton Cordasco · parent 7a13c04 · Browse files · 2 files+11 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−0 removed

  • tests:+8 added−0 removed
  • other:+3 added−0 removed

2 files+11 added−0 removed

modified:src/requests/adapters.py+3 added
388 unmodified lines
389 proxy_scheme = urlparse(proxy).scheme.lower()390 using_socks_proxy = proxy_scheme.startswith("socks")391392 url = request.path_url393 if url.startswith("//"): # Don't confuse urllib3394 url = f"/{url.lstrip('/')}"395396 if is_proxied_http_request and not using_socks_proxy:397 url = urldefragauth(request.url)398399 return url
141 unmodified lines
added:tests/test_adapters.py+8 added
1import requests.adapters234def test_request_url_trims_leading_path_separators():5 """See also https://github.com/psf/requests/issues/6643."""6 a = requests.adapters.HTTPAdapter()7 p = requests.Request(method="GET", url="http://127.0.0.1:10000//v:h").prepare()8 assert "/v:h" == a.request_url(p, {})