From: Jayson Vantuyl Date: Wed, 30 Oct 2013 08:35:54 +0000 (-0700) Subject: loosen URL handling for non-native URL schemes X-Git-Tag: upstream/2.2.1~42^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b149be5d864cc7f65ac22113db3d0e4d2ed2b49e;p=platform%2Fupstream%2Fpython-requests.git loosen URL handling for non-native URL schemes --- diff --git a/AUTHORS.rst b/AUTHORS.rst index 62e0111..67a818b 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -141,3 +141,4 @@ Patches and Suggestions - Vikram Oberoi @voberoi - Can Ibanoglu @canibanoglu - Thomas Weißschuh @t-8ch +- Jayson Vantuyl @kagato diff --git a/requests/models.py b/requests/models.py index f82f56a..9cce36a 100644 --- a/requests/models.py +++ b/requests/models.py @@ -320,6 +320,11 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): except UnicodeDecodeError: pass + # Don't do any URL preparation for oddball schemes + if ':' in url and not url.lower().startswith('http'): + self.url = url + return + # Support for unicode domain names and paths. scheme, auth, host, port, path, query, fragment = parse_url(url) diff --git a/test_requests.py b/test_requests.py index 754581e..ee7d5d1 100755 --- a/test_requests.py +++ b/test_requests.py @@ -683,6 +683,18 @@ class RequestsTestCase(unittest.TestCase): assert p.headers['Content-Length'] == length + def test_oddball_schemes_dont_check_URLs(self): + test_urls = ( + 'data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==', + 'file:///etc/passwd', + 'magnet:?xt=urn:btih:be08f00302bc2d1d3cfa3af02024fa647a271431', + ) + for test_url in test_urls: + req = requests.Request('GET', test_url) + preq = req.prepare() + assert test_url == preq.url + + class TestContentEncodingDetection(unittest.TestCase): def test_none(self):