Opened 7 years ago

Closed 4 years ago

#12140 closed Bug (fixed)

urlencode empty list encoding bug & fix

Reported by: aneil Owned by: nobody
Component: HTTP handling Version: master
Severity: Normal Keywords: urlencode
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Julien Phalip)

django.utils.http.urlencode doesn't behave the same as urllib.urlencode for empty lists:

urllib.urlencode({'foo':[]},True) => ''

django.utils.http.urlencode({'foo':[]},True) => 'foo=%5B%5D'

The attached diff has a change at line 557 in trunk/django/utils/http.py:

-         isinstance(v, (list,tuple)) and [smart_str(i) for i in v] or smart_str(v))
+         [smart_str(i) for i in v] if isinstance(v, (list,tuple)) else smart_str(v))

Attached.

Attachments (2)

urlencode.diff (504 bytes) - added by aneil 7 years ago.
urlencode empty list bug patch
12140-2.diff (1.6 KB) - added by Claude Paroz 5 years ago.
Patch updated to current trunk

Download all attachments as: .zip

Change History (12)

Changed 7 years ago by aneil

Attachment: urlencode.diff added

urlencode empty list bug patch

comment:1 Changed 7 years ago by aneil

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

Change is at line 41, not line 557.

comment:2 Changed 7 years ago by Russell Keith-Magee

Needs tests: set
Triage Stage: UnreviewedAccepted

comment:3 Changed 6 years ago by floguy

Needs tests: unset
Version: 1.1SVN

I've updated the patch to include tests for this. It's all isolated in a branch here: http://github.com/ericflo/django/compare/ticket12140

comment:4 Changed 5 years ago by Matt McClanahan

Severity: Normal
Type: Bug

comment:5 Changed 5 years ago by Julien Phalip

Patch needs improvement: set

The tests would need to be rewritten using unittests since this is now Django's preferred way.

comment:6 Changed 5 years ago by Julien Phalip

Description: modified (diff)

Reformatted description.

comment:7 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:8 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

Changed 5 years ago by Claude Paroz

Attachment: 12140-2.diff added

Patch updated to current trunk

comment:9 Changed 5 years ago by Claude Paroz

Patch needs improvement: unset

comment:10 Changed 4 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In [fe873e276527534b3c0c22f457ee314cf029ced4]:

Fixed #12140 -- Fixed http.urlencode result for empty lists

Thanks aneil for the report and the initial patch.

Note: See TracTickets for help on using tickets.
Back to Top