Opened 4 years ago

Closed 4 years ago

#16842 closed Bug (fixed)

RedirectView (class based) query string format bug

Reported by: slafs 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 accuser 4 years ago.
django-redirects-querystring.patch (2.4 KB) - added by jamey@… 4 years ago.
16842-3.diff (1.7 KB) - added by claudep 4 years ago.
Patch updated to current trunk

Download all attachments as: .zip

Change History (10)

comment:1 Changed 4 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by accuser

  • 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 4 years ago by accuser (previous) (diff)

Changed 4 years ago by accuser

comment:3 Changed 4 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 4 years ago by aaugustin

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

Changed 4 years ago by jamey@…

comment:5 Changed 4 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 4 years ago by claudep

Patch updated to current trunk

comment:6 Changed 4 years ago by claudep

  • Needs tests unset
  • Triage Stage changed from Accepted to Ready 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 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

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