don't prepare URLs for oddball schemes

This commit is contained in:
Jayson Vantuyl
2013-10-30 01:35:54 -07:00
parent 2e196be143
commit a9ec28a1b4
3 changed files with 15 additions and 0 deletions
+5
View File
@@ -327,6 +327,11 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
raise MissingSchema("Invalid URL {0!r}: No schema supplied. "
"Perhaps you meant http://{0}?".format(url))
# Don't do any URL preparation for oddball schemes
if scheme.lower() not in ('http', 'https'):
self.url = url
return
if not host:
raise InvalidURL("Invalid URL %r: No host supplied" % url)
+2
View File
@@ -365,6 +365,8 @@ def parse_url(url):
# Scheme
if '://' in url:
scheme, url = url.split('://', 1)
elif ':' in url:
scheme, url = url.split(':', 1)
# Find the earliest Authority Terminator
# (http://tools.ietf.org/html/rfc3986#section-3.2)
+8
View File
@@ -678,6 +678,14 @@ class RequestsTestCase(unittest.TestCase):
assert p.headers['Content-Length'] == length
def test_oddball_schemes_dont_check_URLs(self):
r1 = requests.Request('GET', 'data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==')
r1.prepare()
r2 = requests.Request('GET', 'file:///etc/passwd')
r2.prepare()
r3 = requests.Request('GET', 'magnet:?xt=urn:btih:be08f00302bc2d1d3cfa3af02024fa647a271431')
r3.prepare()
class TestContentEncodingDetection(unittest.TestCase):
def test_none(self):