diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2018-12-27 11:19:55 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-12-27 11:19:55 -0500 |
| commit | 6fe9c45b725cd21eacbb50263bd3449e1a3edf17 (patch) | |
| tree | 76c94d830c0c1e17d1d7580743908eb0aacc134e /django/utils | |
| parent | 293db9eb36e42e8ba976c2639800020d04b95deb (diff) | |
Fixed #30024 -- Made urlencode() and Client raise TypeError when None is passed as data.
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/http.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/django/utils/http.py b/django/utils/http.py index db18e57803..de1ea71368 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -91,20 +91,31 @@ def urlencode(query, doseq=False): query = query.items() query_params = [] for key, value in query: - if isinstance(value, (str, bytes)): + if value is None: + raise TypeError( + 'Cannot encode None in a query string. Did you mean to pass ' + 'an empty string or omit the value?' + ) + elif isinstance(value, (str, bytes)): query_val = value else: try: - iter(value) + itr = 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_val = [] + for item in itr: + if item is None: + raise TypeError( + 'Cannot encode None in a query string. Did you ' + 'mean to pass an empty string or omit the value?' + ) + elif not isinstance(item, bytes): + item = str(item) + query_val.append(item) query_params.append((key, query_val)) return original_urlencode(query_params, doseq) |
