Opened 5 years ago

Closed 5 years ago

#13572 closed (fixed)

QueryDict.copy().encoding is not set correctly

Reported by: adammck Owned by: nobody
Component: HTTP handling Version: master
Severity: Keywords: querydict, mutable, copy, encoding
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When QueryDict.copy() is called, a new (mutable) querydict is returned, but its 'encoding' attr is not set. This results in the copy being re-encoded wrongly. For example, this works correctly:

>>> q = QueryDict('foo=bar', encoding='rot_13')
>>> q.encoding, q.urlencode()
('foo=bar', 'rot_13')

But this is clearly wrong:

>>> q = QueryDict('foo=bar', encoding='rot_13').copy()
>>> q.encoding, q.urlencode()
('sbb=one', 'utf-8')

Oops! Patch attached, and regression tests which better illustrate the problem.

Attachments (3)

querydict-copy-encoding-tests.patch (891 bytes) - added by adammck 5 years ago.
querydict-copy-encoding-fix.patch (910 bytes) - added by adammck 5 years ago.
querydict-copy-encoding-fix-and-tests.patch (1.8 KB) - added by adammck 5 years ago.

Download all attachments as: .zip

Change History (8)

Changed 5 years ago by adammck

Changed 5 years ago by adammck

comment:1 follow-up: Changed 5 years ago by Alex

  • Component changed from Uncategorized to HTTP handling
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

comment:2 in reply to: ↑ 1 Changed 5 years ago by adammck

What needs improvement? It appears to be a pretty isolated problem with a simple fix.

comment:3 Changed 5 years ago by Alex

  • Patch needs improvement unset

Bah, I didn't notice that there were 2 patches, one with tests and the other with a patch. Can you combine those into a single diff.

Changed 5 years ago by adammck

comment:4 Changed 5 years ago by Alex

  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 5 years ago by jacob

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

(In [13314]) Fixed #13572: copies of QueryDicts now have their encoding set correctly.

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