prevent directives from polluting rendering context

This commit is contained in:
Géry Debongnie
2019-01-25 09:24:21 +01:00
parent 299a6b4977
commit 2894d74db9
2 changed files with 16 additions and 0 deletions
+3
View File
@@ -192,6 +192,9 @@ export class QWeb {
const doc = this.parsedTemplates[name];
const ctx = new Context();
// this is necessary to prevent some directives (t-forach for ex) to
// pollute the rendering context by adding some keys in it.
ctx.addLine("context = Object.create(context)");
const mainNode = doc.firstChild!;
this._compileNode(mainNode, ctx);
+13
View File
@@ -566,6 +566,19 @@ describe("foreach", () => {
const expected = `<div>[0:a1-even][1:b2-odd][2:c3-even]</div>`;
expect(result).toBe(expected);
});
test("does not pollute the rendering context", () => {
const qweb = new QWeb();
qweb.addTemplate(
"test",
`<div>
<t t-foreach="[1]" t-as="item"><t t-esc="item"/></t>
</div>`
);
const context = {};
renderToString(qweb, "test", context);
expect(Object.keys(context).length).toBe(0);
});
});
describe("misc", () => {