[FIX] base, test_assetsbundle, web: multiple broken XML files in assets

When there are multiple broken XML files in an assets bundle. During the
bundle processing, a template containing the parsing error message is
returned for each XML file that is broken.

Before this commit, each of the returned templates had the same name,
raising another error ("Template already exists in module").

Now, all the returned templates has unique names.

closes odoo/odoo#141568

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Jorge Pinna Puissant
2023-11-13 10:31:46 +00:00
parent 7c617cc30c
commit d1fed769d6
6 changed files with 32 additions and 5 deletions
+6 -1
View File
@@ -231,7 +231,12 @@ registry.category("xml_templates").addEventListener("UPDATE", (ev) => {
if (doc.querySelector("parsererror")) {
// The generated error XML is non-standard so we log the full content to
// ensure that the relevant info is actually logged.
throw new Error(doc.querySelector("parsererror").textContent.trim());
let strError = "";
const nodes = doc.querySelectorAll("parsererror");
for (const node of nodes) {
strError += node.textContent.trim() + "\n";
}
throw new Error(strError);
}
for (const element of doc.querySelectorAll("templates > [t-name]")) {
+1 -1
View File
@@ -902,7 +902,7 @@ class XMLAsset(WebAsset):
try:
root = etree.fromstring(content.encode('utf-8'), parser=parser)
except etree.XMLSyntaxError as e:
return f'<t t-name="parsing_error"><parsererror>Invalid XML template: {self.url} \n {e.msg} </parsererror></t>'
return f'<t t-name="parsing_error{self.url.replace("/","_")}"><parsererror>Invalid XML template: {self.url} \n {e.msg} </parsererror></t>'
if root.tag in ('templates', 'template'):
return ''.join(etree.tostring(el, encoding='unicode') for el in root)
return etree.tostring(root, encoding='unicode')
@@ -65,6 +65,10 @@
'test_assetsbundle.broken_xml': [
'test_assetsbundle/static/invalid_src/xml/invalid_xml.xml',
],
'test_assetsbundle.multiple_broken_xml': [
'test_assetsbundle/static/invalid_src/xml/invalid_xml.xml',
'test_assetsbundle/static/invalid_src/xml/second_invalid_xml.xml',
],
},
'license': 'LGPL-3',
}
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="test_assetsvundle.invalid_xml">
<t t-name="test_assetsbundle.invalid_xml">
<SomeComponent>content<SomeComponent/>
</t>
</templates>
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="test_assetsbundle.second_invalid_xml">
<SomeComponent>content</SomeComponent>
</t>
</templates>
@@ -638,10 +638,21 @@ class TestXMLAssetsBundle(FileTouchable):
"""
self.bundle = self._get_asset('test_assetsbundle.broken_xml')
# there shouldn't be any test_assetsvundle.invalid_xml template.
# there shouldn't be any test_assetsbundle.invalid_xml template.
# there should be an parsing_error template with the parsing error message.
self.assertEqual(self.bundle.xml(),
'<t t-name="parsing_error"><parsererror>Invalid XML template: /test_assetsbundle/static/invalid_src/xml/invalid_xml.xml \n Opening and ending tag mismatch: SomeComponent line 4 and t, line 5, column 7 </parsererror></t>',
'<t t-name="parsing_error_test_assetsbundle_static_invalid_src_xml_invalid_xml.xml"><parsererror>Invalid XML template: /test_assetsbundle/static/invalid_src/xml/invalid_xml.xml \n Opening and ending tag mismatch: SomeComponent line 4 and t, line 5, column 7 </parsererror></t>',
"the parsing error should be shown")
def test_02_multiple_broken_xml(self):
""" Checks that a bundle with multiple broken xml returns a comprehensive error message.
"""
self.bundle = self._get_asset('test_assetsbundle.multiple_broken_xml')
# there shouldn't be any test_assetsbundle.invalid_xml template or test_assetsbundle.second_invalid_xml template.
# there should be two parsing_error templates with the parsing error message for each file.
self.assertEqual(self.bundle.xml(),
'<t t-name="parsing_error_test_assetsbundle_static_invalid_src_xml_invalid_xml.xml"><parsererror>Invalid XML template: /test_assetsbundle/static/invalid_src/xml/invalid_xml.xml \n Opening and ending tag mismatch: SomeComponent line 4 and t, line 5, column 7 </parsererror></t><t t-name="parsing_error_test_assetsbundle_static_invalid_src_xml_second_invalid_xml.xml"><parsererror>Invalid XML template: /test_assetsbundle/static/invalid_src/xml/second_invalid_xml.xml \n XML declaration allowed only at the start of the document, line 2, column 6 </parsererror></t>',
"the parsing error should be shown")