From e6b0d06e3e40940e9b1f43335d67761268bdb980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Fri, 29 Mar 2019 15:37:42 +0100 Subject: [PATCH] fix: make sure qweb throw error if invalid templates --- src/qweb.ts | 3 +++ tests/qweb.test.ts | 6 ++++++ 2 files changed, 9 insertions(+) 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", ``); expect(() => qweb.addTemplate("test", "
")).toThrow("already defined"); }); + + test("loadTemplates throw if parser error", () => { + expect(() => { + qweb.loadTemplates(">"); + }).toThrow("Invalid XML in template"); + }); }); describe("t-esc", () => {