diff options
| author | François Freitag <mail+github@franek.fr> | 2017-10-09 13:20:01 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-10-12 09:08:33 -0400 |
| commit | 41be85862d9067a809ccf3707d2a22dfef23d99a (patch) | |
| tree | 979b1e01378ab1a38fa8f00718a804e59a640522 /django/utils | |
| parent | 4d60261b2a77460b4c127c3d832518b95e11a0ac (diff) | |
Fixed #28679 -- Fixed urlencode()'s handling of bytes.
Regression in fee42fd99ee470528858c2ccb3621135c30ec262.
Thanks Claude Paroz, Jon Dufresne, and Tim Graham for the guidance.
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/http.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/django/utils/http.py b/django/utils/http.py index c13f44602b..4fbb786d89 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -88,11 +88,24 @@ def urlencode(query, doseq=False): query = query.lists() elif hasattr(query, 'items'): query = query.items() - return original_urlencode( - [(k, [str(i) for i in v] if isinstance(v, (list, tuple)) else str(v)) - for k, v in query], - doseq - ) + query_params = [] + for key, value in query: + if isinstance(value, (str, bytes)): + query_val = value + else: + try: + iter(value) + except TypeError: + query_val = value + else: + # Consume generators and iterators, even when doseq=True, to + # work around https://bugs.python.org/issue31706. + query_val = [ + item if isinstance(item, bytes) else str(item) + for item in value + ] + query_params.append((key, query_val)) + return original_urlencode(query_params, doseq) def cookie_date(epoch_seconds=None): |
