loosen URL handling for non-native URL schemes
authorJayson Vantuyl <jayson@aggressive.ly>
Wed, 30 Oct 2013 08:35:54 +0000 (01:35 -0700)
committerJayson Vantuyl <jayson@aggressive.ly>
Fri, 15 Nov 2013 09:25:32 +0000 (01:25 -0800)
AUTHORS.rst
requests/models.py
test_requests.py

index 62e01116ebc13e563b385a3396cf3f61aa8fb607..67a818ba4264ab3c8c35594963d13408ab081e2a 100644 (file)
@@ -141,3 +141,4 @@ Patches and Suggestions
 - Vikram Oberoi @voberoi
 - Can Ibanoglu <can.ibanoglu@gmail.com> @canibanoglu
 - Thomas Weißschuh <thomas@t-8ch.de> @t-8ch
+- Jayson Vantuyl <jayson@aggressive.ly> @kagato
index f82f56a3bb1d7c7fe2d41b2593b8b34391dc7cfd..9cce36ac067d220af4b11c00b65ae6f25450d18c 100644 (file)
@@ -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)
 
index 754581e1a965d61915d8d633c26560292ec83dc9..ee7d5d13592ac179044eb3d0b52a276ac8cfd8ef 100755 (executable)
@@ -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):