[FIX] qweb: do not leak values in global context in rare cases

In some very rare cases (such as the use of the t-foreach directive),
Owl did leak the values in the render context in the global context.
This was due to the fact that the compiled template looked like this:

let _3 = _4 = _5;

instead of

let _3 = _5;
let _4 = _5;
This commit is contained in:
Géry Debongnie
2021-10-19 15:55:57 +02:00
committed by aab-odoo
parent c0f495661d
commit 6e185f987b
6 changed files with 130 additions and 38 deletions
+17
View File
@@ -0,0 +1,17 @@
import { QWeb } from "../../src/qweb/index";
import { renderToString } from "../helpers";
describe("memory", () => {
test("t-foreach does not leak stuff in global scope", () => {
let qweb = new QWeb();
const initialNumberOfGlobals = Object.keys(window).length;
qweb.addTemplate(
"test",
`<p><t t-foreach="[3, 2, 1]" t-as="item"><t t-esc="item"/></t></p>`
);
const result = renderToString(qweb, "test");
const expected = `<p>321</p>`;
expect(result).toBe(expected);
expect(Object.keys(window).length).toBe(initialNumberOfGlobals);
});
});