Fix unicode problems in web plugin

Added Exception to the web plugin to catch non latin-1 characters and change them to ascii chars.
Added Description to the changelog file
This commit is contained in:
Waweic 2018-03-01 11:56:38 +01:00
parent b6b25cfec9
commit 4df313e3ce
2 changed files with 10 additions and 5 deletions

View file

@ -24,6 +24,7 @@ import flask
from flask import g from flask import g
from werkzeug.routing import BaseConverter, PathConverter from werkzeug.routing import BaseConverter, PathConverter
import os import os
from unidecode import unidecode
import json import json
import base64 import base64
@ -224,12 +225,12 @@ def item_file(item_id):
item_path = util.syspath(item.path) item_path = util.syspath(item.path)
else: else:
item_path = util.py3_path(item.path) item_path = util.py3_path(item.path)
try:
os.path.basename(util.py3_path(item.path)).encode("latin-1", "strict") #Imitate http.server behaviour
response = flask.send_file(item_path,as_attachment=True)
except UnicodeEncodeError:
response = flask.send_file(item_path,as_attachment=True, attachment_filename=unidecode(os.path.basename(util.py3_path(item.path))))
response = flask.send_file(
item_path,
as_attachment=True,
attachment_filename=os.path.basename(util.py3_path(item.path)),
)
response.headers['Content-Length'] = os.path.getsize(item_path) response.headers['Content-Length'] = os.path.getsize(item_path)
return response return response

View file

@ -75,6 +75,10 @@ Fixes:
album art would not work and throw an exception. It now works as expected. album art would not work and throw an exception. It now works as expected.
Additionally, the server will now return a 404 response when the album id Additionally, the server will now return a 404 response when the album id
is unknown, instead of a 500 response and a thrown exception. :bug:`2823` is unknown, instead of a 500 response and a thrown exception. :bug:`2823`
* :doc:`/plugins/web`: In a python 3 enviroment, the server would throw an
exception if non latin-1 characters where in the File name.
It now checks if non latin-1 characters are in the filename and changes
them to ascii-characters in that case :bug:`2815`
For developers: For developers: