bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.44k stars 1.47k forks source link

Formsdict attribute like access returns invalid values for parameters submitted with unicode characters #774

Open ctengiz opened 9 years ago

ctengiz commented 9 years ago

Suppose we got a parameter submitted which has the value of 'ğüşiöç': aparam = 'ğüşiöç'

If request.method is 'GET':

request.GET.aparam returns : 'ğüşiöç' --> ok request.GET['aparam'] returns : 'ğüşiöç'--> ??

If request method is 'POST':

request.POST.aparam returns : '' --> ?? request.POST['aparam'] returns : 'ğüşiöç--> ok

This behaviour interrupts clean and consistent coding style. When I need to access request form parameters I need to remember correct way to access them rather than simply writing request.POST.aparam.

Is this behaaviour is intended way or is this a bug or am I missing sth?

PS: Tested with Python 3.4, Python 3.2, and latest bottle github clone code

TIA

eric-wieser commented 9 years ago

This is by design:

Additionally to the normal dict-like item access methods (which return unmodified data as native strings), this container also supports attribute-like access to its values. Attributes are automatically de- or recoded to match :attr:input_encoding (default: 'utf8'). Missing attributes default to an empty string.

Try comparing type(request.GET.aparam) with type(request.GET['aparam'])

Note that .query and .forms seem to be the more canonical way of spelling .GET and .POST, respectively

defnull commented 9 years ago

We should probably change the behavior of item-lookup at some point. This inconsistency was introduced to keep backwards-compatibility but the re-encoding behavior makes much more sense and should be the default. Unfortunately it is not easy to find an upgrade path for this kind of behavior changes.

onny commented 9 years ago

Also encountered this bug, thanks for the info! https://gist.github.com/onny/c7ca3509e223493cb684

logannc commented 6 years ago

If anyone has time, please take a look at my PR which attempts to fix this issue. Thank you!