[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#132267

X-original-commit: ba6f90fac142ae53995f4fce4b75799e61b95b6c
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
Signed-off-by: Saurabh Choraria (sauc) <sauc@odoo.com>
This commit is contained in:
Saurabh Choraria
2023-08-19 10:05:45 +02:00
parent d5bee8b86f
commit ea9d6649ee
2 changed files with 16 additions and 1 deletions
+10
View File
@@ -14994,6 +14994,16 @@ msgstr ""
msgid "Error message returned when the constraint is violated."
msgstr ""
#. module: base
#. odoo-python
#: code:addons/translate.py:0
#, python-format
msgid ""
"Error while parsing view:\n"
"\n"
"%s"
msgstr ""
#. module: base
#. odoo-python
#: code:addons/base/models/ir_ui_view.py:0
+6 -1
View File
@@ -26,6 +26,7 @@ from lxml import etree, html
from psycopg2.extras import Json
import odoo
from odoo.exceptions import UserError
from odoo.modules.module import get_resource_path
from . import config, pycompat
from .misc import file_open, get_iso_codes, SKIPPED_ELEMENT_TYPES
@@ -293,7 +294,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')