From b149be5d864cc7f65ac22113db3d0e4d2ed2b49e Mon Sep 17 00:00:00 2001 From: Jayson Vantuyl Date: Wed, 30 Oct 2013 01:35:54 -0700 Subject: [PATCH] loosen URL handling for non-native URL schemes --- AUTHORS.rst | 1 + requests/models.py | 5 +++++ test_requests.py | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index 62e01116eb..67a818ba42 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 f82f56a3bb..9cce36ac06 100644 --- a/requests/models.py +++ b/requests/models.py @@ -320,6 +320,11 @@ def prepare_url(self, url, params): 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 754581e1a9..ee7d5d1359 100755 --- a/test_requests.py +++ b/test_requests.py @@ -683,6 +683,18 @@ def test_autoset_header_values_are_native(self): 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):