mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
prevent directives from polluting rendering context
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user