Skip to content

Commit

Permalink
loosen URL handling for non-native URL schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
jvantuyl committed Nov 15, 2013
1 parent a123f83 commit b149be5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b149be5

Please sign in to comment.