mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
fix: make sure qweb throw error if invalid templates
This commit is contained in:
@@ -300,6 +300,9 @@ export class QWeb {
|
|||||||
loadTemplates(xmlstr: string) {
|
loadTemplates(xmlstr: string) {
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
const doc = parser.parseFromString(xmlstr, "text/xml");
|
const doc = parser.parseFromString(xmlstr, "text/xml");
|
||||||
|
if (doc.getElementsByTagName("parsererror").length) {
|
||||||
|
throw new Error("Invalid XML in template");
|
||||||
|
}
|
||||||
const templates = doc.getElementsByTagName("templates")[0];
|
const templates = doc.getElementsByTagName("templates")[0];
|
||||||
if (!templates) {
|
if (!templates) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -101,6 +101,12 @@ describe("error handling", () => {
|
|||||||
qweb.addTemplate("test", `<t></t>`);
|
qweb.addTemplate("test", `<t></t>`);
|
||||||
expect(() => qweb.addTemplate("test", "<div/>")).toThrow("already defined");
|
expect(() => qweb.addTemplate("test", "<div/>")).toThrow("already defined");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("loadTemplates throw if parser error", () => {
|
||||||
|
expect(() => {
|
||||||
|
qweb.loadTemplates("<templates><abc>></templates>");
|
||||||
|
}).toThrow("Invalid XML in template");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("t-esc", () => {
|
describe("t-esc", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user