diff --git a/src/qweb.ts b/src/qweb.ts
index 56154547..2c73a072 100644
--- a/src/qweb.ts
+++ b/src/qweb.ts
@@ -300,6 +300,9 @@ export class QWeb {
loadTemplates(xmlstr: string) {
const parser = new DOMParser();
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];
if (!templates) {
return;
diff --git a/tests/qweb.test.ts b/tests/qweb.test.ts
index 60f2c793..2fda7ca9 100644
--- a/tests/qweb.test.ts
+++ b/tests/qweb.test.ts
@@ -101,6 +101,12 @@ describe("error handling", () => {
qweb.addTemplate("test", `