Opened 5 years ago

Closed 7 months ago

#12432 closed Bug (wontfix)

After setting encoding in view, request.REQUEST is not deleted

Reported by: xiaket Owned by: nobody
Component: HTTP handling Version: master
Severity: Normal Keywords: encoding request.REQUEST http
Cc: xiaket@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Steps to repeat this bug

>>> str = "msg=%28%D0%A1%C3%B7%C9%B3%29"     # GBK encoded URL.
>>> from django.core.handlers.wsgi import WSGIRequest
>>> fakeenv = {'QUERY_STRING': str, 'REQUEST_METHOD': 'GET'}
>>> request = WSGIRequest(fakeenv)
>>> request.encoding        # This would return nothing, meaning no encoding is set yet.
>>> request.GET['msg']    
u'(\u0421\xf7\u0273)'
>>> request.REQUEST['msg']
u'(\u0421\xf7\u0273)'       # This is not correctly decoded, which is accepted, because no encoding is given.
>>> request.encoding = "GBK"# Set encoding
>>> request.GET['msg']  
u'(\u5c0f\u6885\u6c99)'     # GET is deleted and regenerated, so it's decoded correctly.
>>> request.REQUEST['msg']
u'(\u0421\xf7\u0273)'       # This is not acceptable, for we have provided the correct encoding.

Affected Code

The problem is, in the definition of HTTPRequest class, a _set_encoding method is provided, which would delete GET and POST after view function have provided encoding information. When the view function ask for GET and POST again, they would be re-generated. However, both modpython and wsgi request class added a shortcut dictionary named REQUEST, which is not deleted upon encoding change.

IMHO, design decision would be required as to whether to add request.REQUEST into the base HTTPRequest class and modify the _set_encoding function, or to override default _set_encoding method in both modpython and wsgi request class.

Change History (5)

comment:1 Changed 5 years ago by russellm

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

comment:2 Changed 4 years ago by mattmcc

  • Severity set to Normal
  • Type set to Bug

comment:3 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 7 months ago by timo

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

request.REQUEST is deprecated and will be removed in Django 1.9, so I think we can "won't fix" this.

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