Skip to content
Myr

Correct handling of URLs with quoted slashes.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Ryan Kelly · committed by Ryan Kelly · parent 76dacaf · Browse files · 2 files+15 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−3 removed

  • other:+15 added−3 removed

2 files+15 added−3 removed

modified:requests/models.py+3 added-3 removed
25 unmodified lines
26from .exceptions import (27 Timeout, URLRequired, TooManyRedirects, HTTPError, ConnectionError)28from .utils import (29 get_unicode_from_response, stream_decode_response_unicode,30 decode_gzip, stream_decode_gzip, guess_filename)30 decode_gzip, stream_decode_gzip, guess_filename, requote_path)313233REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)34
178 unmodified lines
213214 # Facilitate non-RFC2616-compliant 'location' headers215 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')216 if not urlparse(url).netloc:217 url = urljoin(r.url, urllib.quote(urllib.unquote(url)))217 url = urljoin(r.url, requote_path(url))218219 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4220 if r.status_code is codes.see_other:221 method = 'GET'
76 unmodified lines
298299 if isinstance(path, unicode):300 path = path.encode('utf-8')301302 path = urllib.quote(urllib.unquote(path))302 path = requote_path(path)303304 url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))305306 if self._enc_params:
312 unmodified lines
modified:requests/utils.py+12 added
14 unmodified lines
15import os16import random17import re18import zlib19import urllib2021from urllib2 import parse_http_list as _parse_list_header2223
343 unmodified lines
367 if rv:368 yield rv369 except zlib.error:370 pass371372373def requote_path(path):374 """Re-quote the given URL path component.375376 This function passes the given path through an unquote/quote cycle to377 ensure that it is fully and consistenty quoted.378 """379 parts = path.split("/")380 parts = (urllib.quote(urllib.unquote(part), safe="") for part in parts)381 return "/".join(parts)