#30485 closed Bug (fixed)
Unexpected behavior for django.utils.http.urlencode
Reported by: | Johan Lübcke | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | 2.2 |
Severity: | Normal | Keywords: | |
Cc: | François Freitag | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The function django.utils.http.urlencode has been changed to give unexpected result for tuple values (and other iterable objects) in the case when no iterations is expected:
>>> django.utils.http.urlencode(dict(a=('a','b')), doseq=False) 'a=%5B%27a%27%2C+%27b%27%5D'
One would expect the same as the standard library version (Note the first and last characters has been replaced by square brackets):
>>> urllib.parse.urlencode(dict(a=('a', 'b')), doseq=False) 'a=%28%27a%27%2C+%27b%27%29'
If the value is a list, the result if what one would expect:
>>> django.utils.http.urlencode(dict(a=['a','b']), doseq=False) 'a=%5B%27a%27%2C+%27b%27%5D' >>> urllib.parse.urlencode(dict(a=['a', 'b']), doseq=False) 'a=%5B%27a%27%2C+%27b%27%5D'
Note: This is a problem when one has objects that has a __str__
method defined, returning the value one would want to be in the urlencode result, but the object by coincidence is also iterable.
Change History (7)
comment:1 by , 6 years ago
Has patch: | set |
---|
comment:2 by , 6 years ago
Cc: | added |
---|
comment:3 by , 5 years ago
Triage Stage: | Unreviewed → Accepted |
---|
OK, having conferred with Mariusz, I'm going to Accept this as a bug on 2.2, to be fixed in master, rather than backported to 2.2. (We'll look at the final patch before deciding finally there.)
comment:4 by , 5 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Asking François to comment. This is related to #28679.