changeset ac4d56e51695 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=ac4d56e51695
description:
Display decoding error in HTML editor
If the bytes can not be decoded in UTF-8, we should display a nice error
message instead of failing with a 500.
Also if the text is not a string, we must return a 400 as it is a wrong
request.
issue8577
review264451002
diffstat:
trytond/ir/routes.py | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diffs (29 lines):
diff -r 47039caac53e -r ac4d56e51695 trytond/ir/routes.py
--- a/trytond/ir/routes.py Fri Oct 25 23:06:19 2019 +0200
+++ b/trytond/ir/routes.py Wed Oct 30 13:26:38 2019 +0100
@@ -5,6 +5,7 @@
except ImportError:
from http import client as HTTPStatus
+from werkzeug.exceptions import abort
from werkzeug.utils import redirect
from werkzeug.wrappers import Response
@@ -63,9 +64,15 @@
error = gettext('ir.msg_html_editor_save_fail')
csrf_token = get_token(record)
- text = getattr(record, field.name)
+ text = getattr(record, field.name) or ''
if isinstance(text, bytes):
- text = text.decode('utf-8')
+ try:
+ text = text.decode('utf-8')
+ except UnicodeDecodeError as e:
+ error = str(e).replace("'", "\\'")
+ text = ''
+ elif not isinstance(text, str):
+ abort(HTTPStatus.BAD_REQUEST)
title = '%(model)s "%(name)s" %(field)s - %(title)s' % {
'model': field.model.name,
'name': record.rec_name,