Opened 8 years ago

Closed 7 years ago

#16842 closed Bug (fixed)

RedirectView (class based) query string format bug

Reported by: Sławek Ehlert Owned by: nobody
Component: Generic views Version: 1.3
Severity: Normal Keywords:
Cc: alexey.smolsky@…, jamey@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


There is a problem with the new class based RedirectView with query_string = True and some unicode string in QUERY_STRING.
I made a sample of the error on bitbucket

The error that I'm getting is :

 File "/usr/local/lib/python2.7/dist-packages/django/views/generic/" in get_redirect_url
 146.             return url % kwargs

 Exception Type: ValueError at /test/
 Exception Value: unsupported format character 'C' (0x43) at index 15

Basically the problem is when a QUERY_STRING contains some unicode chars that were previously encoded with urlencode (i.e. {{ request.GET.urlencode }} - like in my bitbucket example ) and for example polish "ż" is encoded as "%C5" which breaks the "%" formatting.

The relevant topic on Google Groups is here

As Karen M. Tracey suggested I opened this ticket.

Attachments (3)

django13-redirects.patch (1.5 KB) - added by Alexey Smolsky 8 years ago.
django-redirects-querystring.patch (2.4 KB) - added by jamey@… 7 years ago.
16842-3.diff (1.7 KB) - added by Claude Paroz 7 years ago.
Patch updated to current trunk

Download all attachments as: .zip

Change History (10)

comment:1 Changed 8 years ago by Alex Gaynor

Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by Alexey Smolsky

Cc: alexey.smolsky@… added
Has patch: set
Needs tests: set

I think kwargs should be applied before concatenation with query string. Patch attached.

Last edited 8 years ago by Alexey Smolsky (previous) (diff)

Changed 8 years ago by Alexey Smolsky

Attachment: django13-redirects.patch added

comment:3 Changed 7 years ago by jamey@…

Cc: jamey@… added

I believe accuser's patch is the correct fix for this bug, which I just ran into. I hope it will be included in 1.4, though I'd also like a stable release on the 1.3 series to include this patch and the fix for #15852.

comment:4 Changed 7 years ago by Aymeric Augustin

Currently, this patch needs tests, which prevents it from being committed.

Changed 7 years ago by jamey@…

comment:5 Changed 7 years ago by jamey@…

OK, I've added a test case to accuser's patch, which fails without the patch and passes with it. Good enough?

Changed 7 years ago by Claude Paroz

Attachment: 16842-3.diff added

Patch updated to current trunk

comment:6 Changed 7 years ago by Claude Paroz

Needs tests: unset
Triage Stage: AcceptedReady for checkin

The patch could not be applied to trunk. The part about the function-based generic view "redirect_to" has been fixed in r17034. Just uploaded a new patch with that part removed.

comment:7 Changed 7 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

In [17625]:

Fixed #16842 -- Modified the RedirectView to correctly handle query strings with percent symbols. Thanks, accuser, jamey@… and Claude Paroz.

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