From 4318455684aecb487c8db3fd9265811d09b5b8a9 Mon Sep 17 00:00:00 2001 From: Saurabh Choraria <sauc@odoo.com> Date: Thu, 27 Jul 2023 12:36:59 +0000 Subject: [PATCH] [FIX] base: handle error when editing comment in view's architecture Currently, When the user is adding a double hyphen or space or anything within a comment in a view's architecture and tries to save the view, then an error occurs. To reproduce the issue: 1. Go to Settings > Technical > Views > open a view. 2. In View Architecture comment out a line. 3. Add a double hyphen or space or anything within the comment. 4. Then save manually, the error will occur. To solve this issue the error has been handled using a try-except block in 'parse_html' method. sentry-4306359331 closes odoo/odoo#129969 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com> --- odoo/addons/base/i18n/base.pot | 9 +++++++++ odoo/tools/translate.py | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/i18n/base.pot b/odoo/addons/base/i18n/base.pot index 727013073a7b..7f1d7f933ef7 100644 --- a/odoo/addons/base/i18n/base.pot +++ b/odoo/addons/base/i18n/base.pot @@ -12024,6 +12024,15 @@ msgstr "" msgid "Error message returned when the constraint is violated." msgstr "" +#. module: base +#: code:addons/translate.py:0 +#, python-format +msgid "" +"Error while parsing view:\n" +"\n" +"%s" +msgstr "" + #. module: base #: code:addons/base/models/ir_ui_view.py:0 #, python-format diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index 6ba57274d9f6..e053398d8dc0 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -22,6 +22,7 @@ from babel.messages import extract from lxml import etree, html import odoo +from odoo.exceptions import UserError from . import config, pycompat from .misc import file_open, get_iso_codes, SKIPPED_ELEMENT_TYPES @@ -295,7 +296,11 @@ def serialize_xml(node): _HTML_PARSER = etree.HTMLParser(encoding='utf8') def parse_html(text): - return html.fragment_fromstring(text, parser=_HTML_PARSER) + try: + parse = html.fragment_fromstring(text, parser=_HTML_PARSER) + except TypeError as e: + raise UserError(_("Error while parsing view:\n\n%s") % e) from e + return parse def serialize_html(node): return etree.tostring(node, method='html', encoding='unicode') -- GitLab