mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #3021 from geckon/proposed/3.0.0
Fix #3017: Whitespace characters surrounding a URL should be ignored
This commit is contained in:
@@ -165,3 +165,4 @@ Patches and Suggestions
|
||||
- Robin Linderborg (`@vienno <https://github.com/vienno>`_)
|
||||
- Brian Samek (`@bsamek <https://github.com/bsamek>`_)
|
||||
- Dmitry Dygalo (`@Stranger6667 <https://github.com/Stranger6667>`_)
|
||||
- Tomáš Heger (`@geckon <https://github.com/geckon>`_)
|
||||
|
||||
@@ -335,6 +335,9 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
else:
|
||||
url = unicode(url) if is_py2 else str(url)
|
||||
|
||||
# Ignore any leading and trailing whitespace characters.
|
||||
url = url.strip()
|
||||
|
||||
# Don't do any URL preparation for non-HTTP schemes like `mailto`,
|
||||
# `data` etc to work around exceptions from `url_parse`, which
|
||||
# handles RFC 3986 only.
|
||||
|
||||
@@ -1317,6 +1317,17 @@ class TestCaseInsensitiveDict:
|
||||
cid['changed'] = True
|
||||
assert cid != cid_copy
|
||||
|
||||
def test_url_surrounding_whitespace(self, httpbin):
|
||||
"""Test case with URLs surrounded by whitespace characters."""
|
||||
get_url = httpbin('get')
|
||||
# All surrounding whitespaces are supposed to be ignored:
|
||||
assert requests.get(get_url + ' ').status_code == 200
|
||||
assert requests.get(' ' + get_url).status_code == 200
|
||||
assert requests.get(get_url + ' \t ').status_code == 200
|
||||
assert requests.get(' \t' + get_url).status_code == 200
|
||||
assert requests.get(get_url + '\n').status_code == 200
|
||||
# The whitespaces can't be in the middle of the URL though:
|
||||
assert requests.get(get_url + ' abc').status_code == 404
|
||||
|
||||
class TestUtils:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user