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

Unicode encoding not working with <form enctype="multipart/form-data"> #1165

Closed sharpaper closed 1 year ago

sharpaper commented 5 years ago

Problem: when using <form enctype="multipart/form-data">, FormsDict does not return the correct unicode values for input fields.

How to reproduce:

from bottle import route, run, template, get, post, request

@get('/')
def index():
        return """
        <form method="post" enctype="multipart/form-data">
            <input type="text" name="key" />
            <input type="submit" />
        </form>
        """

@post('/')
def index_post():
    print(request.forms['key'])
    print(request.forms.get('key'))
    print(request.forms.key)
    print(request.forms.getunicode('key'))
    return ""

index_post output:

cérémonie
cérémonie

None

but if you remove enctype="multipart/form-data" the output is magically correct:

cérémonie
cérémonie
cérémonie
cérémonie

What is going on? Is this the correct behavior? I don't really understand if it's a bug or not...

sharpaper commented 5 years ago

The explanation here could be that application/x-www-form-urlencoded the POST body is URL-encoded just like a GET query string, whereas multipart/form-data is not URL-encoded. So I think it's a Bottle bug because it tries to encode a string that is already in UTF-8?

defnull commented 5 years ago

The issue was fixed in master ( see #1111 and 5813b87 ) but not back-ported to 0.12 yet.

sharpaper commented 5 years ago

Is Bottle 0.13 available on pypi?

defnull commented 1 year ago

Backportet to 0.12.24