bottle icon indicating copy to clipboard operation
bottle copied to clipboard

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

Open ctengiz opened this issue 10 years ago • 4 comments

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

ctengiz avatar Jul 13 '15 09:07 ctengiz

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

eric-wieser avatar Jul 14 '15 18:07 eric-wieser

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.

defnull avatar Jul 25 '15 11:07 defnull

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

onny avatar Sep 12 '15 20:09 onny

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

logannc avatar Nov 29 '17 00:11 logannc