diff options
| author | Tim Graham <timograham@gmail.com> | 2018-08-02 21:56:26 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-08-02 21:56:43 -0400 |
| commit | 0cfca0f2ccc2050de9de65a28d241d8cafcfe666 (patch) | |
| tree | 6b7c2d58e9ee2e5fea8ed0312d260911f751c186 | |
| parent | 66c0c58cf2bc08233ca7bd1d4973e34cbc2ab2ec (diff) | |
[2.1.x] Fixed #29627 -- Fixed QueryDict.urlencode() crash with non-string values.
Regression in 7d96f0c49ab750799860e42716d7105e11de44de.
Backport of d8e2be459f97f1773c7edf7d37de180139146176 from master
| -rw-r--r-- | django/http/request.py | 2 | ||||
| -rw-r--r-- | docs/releases/2.1.1.txt | 3 | ||||
| -rw-r--r-- | tests/httpwrappers/tests.py | 7 |
3 files changed, 11 insertions, 1 deletions
diff --git a/django/http/request.py b/django/http/request.py index 7c44dbb01e..36d05baf4d 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -520,7 +520,7 @@ class QueryDict(MultiValueDict): return urlencode({k: v}) for k, list_ in self.lists(): output.extend( - encode(k.encode(self.encoding), v.encode(self.encoding)) + encode(k.encode(self.encoding), str(v).encode(self.encoding)) for v in list_ ) return '&'.join(output) diff --git a/docs/releases/2.1.1.txt b/docs/releases/2.1.1.txt index dd9662118d..b9ac90e33b 100644 --- a/docs/releases/2.1.1.txt +++ b/docs/releases/2.1.1.txt @@ -11,3 +11,6 @@ Bugfixes * Fixed a race condition in ``QuerySet.update_or_create()`` that could result in data loss (:ticket:`29499`). + +* Fixed a regression where ``QueryDict.urlencode()`` crashed if the dictionary + contains a non-string value (:ticket:`29627`). diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py index 24260ae610..01ce20f93d 100644 --- a/tests/httpwrappers/tests.py +++ b/tests/httpwrappers/tests.py @@ -114,6 +114,13 @@ class QueryDictTests(SimpleTestCase): self.assertEqual(q.urlencode(), 'next=%2Ft%C3%ABst%26key%2F') self.assertEqual(q.urlencode(safe='/'), 'next=/t%C3%ABst%26key/') + def test_urlencode_int(self): + # Normally QueryDict doesn't contain non-string values but lazily + # written tests may make that mistake. + q = QueryDict(mutable=True) + q['a'] = 1 + self.assertEqual(q.urlencode(), 'a=1') + def test_mutable_copy(self): """A copy of a QueryDict is mutable.""" q = QueryDict().copy() |
