Skip to content
Myr

Revert "Restrict URL preparation to HTTP/HTTPS"

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

This reverts commit 34af72c87d79bd8852e8564c050dd7711c6a08d6.

authored by Cory Benfield · committed by Cory Benfield · parent ca15d48 · Browse files · 2 files+3 added−20 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+3 added−20 removed

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

2 files+3 added−20 removed

modified:requests/models.py+3 added-3 removed
345 unmodified lines
346 # Remove leading whitespaces from url347 url = url.lstrip()348349 # Don't do any URL preparation for non-HTTP schemes like `mailto`,350 # `data`, `http+unix` etc to work around exceptions from `url_parse`,351 # which handles RFC 3986 only.352 if ':' in url and not url.lower().startswith(('http://', 'https://')):350 # `data` etc to work around exceptions from `url_parse`, which351 # handles RFC 3986 only.352 if ':' in url and not url.lower().startswith('http'):353 self.url = url354 return355356 # Support for unicode domain names and paths.
550 unmodified lines
modified:tests/test_requests.py-17 removed
2173 unmodified lines
2174 def test_preparing_bad_url(self, url):2175 r = requests.Request('GET', url=url)2176 with pytest.raises(requests.exceptions.InvalidURL):2177 r.prepare()21782179 @pytest.mark.parametrize(2180 'protocol, url',2181 (2182 ("http+unix://", b"http+unix://%2Fvar%2Frun%2Fsocket/path"),2183 ("http+unix://", u"http+unix://%2Fvar%2Frun%2Fsocket/path"),2184 ("mailto", b"mailto:user@example.org"),2185 ("mailto", u"mailto:user@example.org"),2186 ("data", b"data:SSDimaUgUHl0aG9uIQ=="),2187 )2188 )2189 def test_url_passthrough(self, protocol, url):2190 session = requests.Session()2191 session.mount(protocol, HTTPAdapter())2192 p = requests.Request('GET', url=url)2193 p.prepare()2194 assert p.url == url