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
This commit is contained in:
@@ -5,6 +5,7 @@ try:
|
||||
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 @@ def html_editor(request, pool, model, record, field):
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user