-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UTF8 path string invalid when using app.mount() #602
Comments
|
We have to notice that UTF8 path is generally working: #!/usr/bin/python
# -*- coding: utf-8 -*-
import bottle
import testapp
bottle.debug(True)
app = bottle.Bottle()
@app.route("/test/:category", method=["GET","POST"])
def admin(category):
try:
return category
except Exception(e):
print ("e:"+str(e))
app.run(reloader=True, host='0.0.0.0', port=8080)
run(host="localhost",port=8080)Visiting http://127.0.0.1:8080/test/äöü prints the special chars without any problems :/ |
|
app.mount() accepts special characters if I uncomment/ignore this exception: def _handle(self, environ):
path = environ['bottle.raw_path'] = environ['PATH_INFO']
if py3k:
try:
environ['PATH_INFO'] = path.encode('latin1').decode('utf8')
except UnicodeError:
print("unicode error")
# return HTTPError(400, 'Invalid path string. Expected UTF-8') |
|
The actual bug (or bad design decision) seems to be that bottle overwrites Bottle should not change |
|
This bug is 5 years old and still exists. It creates problems with UTF-8 URL because Bottle returns |
|
To reproduce: go to result: |
|
This issue seems related to this other one: #792 |
|
Also, your exact example works fine for valid utf-8 strings, encoded or not. |
|
The original issue (mounting apps) is still present, though. Pull requests are welcomed. |
|
I faced this bug on my app too. In my case, I avoid the bug as follows and the app works fine. #!/usr/bin/env python3
import functools
import bottle
def pathinfo_adjust_wrapper(func):
# A wrapper for _handle() method
@functools.wraps(func)
def _(environ):
environ["PATH_INFO"] = environ["PATH_INFO"].encode("utf8").decode("latin1")
return func(environ)
return _
api = bottle.Bottle()
api._handle = pathinfo_adjust_wrapper(api._handle)
@api.route("/<path:path>")
def callback(path):
return {"name": path}
application = bottle.default_app()
application.mount("/api/", api)
application.run(host="0.0.0.0")Access to URL "/api/日本語/filename" (this is in Japanese). $ curl 127.0.0.1:8080/api/%E6%97%A5%E6%9C%AC%E8%AA%9E/filename
{"name": "\u65e5\u672c\u8a9e/filename"}It seems to OK. This way does not need any code change on bottle.py. In this code, the I love 💖 the bottle.py framework for developing web apps. Thank you! |
It looks that bottlepy#602 is gone, but I'm not sure when exactly it was fixed. I see that there is a suspicious change [here](bottlepy@d85a698): environ['PATH_INFO'] = path.encode('latin1').decode('utf8', 'ignore') Where original cause of the error was removed and replaced by `'ignore'`. Also fixed deprecation warnings, where: @self.subapp.route('') Does exactly same thing as this: @self.subapp.route('/test/<test>') Where `''` is passed to `route()`, then `makelist()` utility assumes that nothing is passed and falls back to path autogeneration from callbackf unction. Not sure if this is expected behaviour?
It looks that #602 is gone, but I'm not sure when exactly it was fixed. I see that there is a suspicious change [here](d85a698): environ['PATH_INFO'] = path.encode('latin1').decode('utf8', 'ignore') Where original cause of the error was removed and replaced by `'ignore'`. Also fixed deprecation warnings, where: @self.subapp.route('') Does exactly same thing as this: @self.subapp.route('/test/<test>') Where `''` is passed to `route()`, then `makelist()` utility assumes that nothing is passed and falls back to path autogeneration from callbackf unction. Not sure if this is expected behaviour?
test.py:
testapp.py:
Trying to access: http://127.0.0.1:8080/test/äöü results in following error:
Running Python 3.4.0 with python-bottle 0.12.5.
The text was updated successfully, but these errors were encountered: