From 30d2d2e7dc577b543ffec7acd8d96fa3cd7b4831 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 21 Apr 2022 07:06:46 +0000 Subject: [PATCH] [FIX] web: py_js: add "true"/"false" in context Before this commit, py_js was unabled to evaluate expressions containing "true" or "false" (boolean values, JS syntax), which seems reasonnable for a python interpreter. However in Odoo, we often use that syntax in modifiers (e.g. required="true"). For that reason, we need to add those two keywords in the evaluation context. Part-of: odoo/odoo#87522 --- addons/web/static/src/core/py_js/py_builtin.js | 3 +++ addons/web/static/tests/core/py_js/py_interpreter_tests.js | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/addons/web/static/src/core/py_js/py_builtin.js b/addons/web/static/src/core/py_js/py_builtin.js index 9a16bcd57bc..bc57a9b4e21 100644 --- a/addons/web/static/src/core/py_js/py_builtin.js +++ b/addons/web/static/src/core/py_js/py_builtin.js @@ -58,4 +58,7 @@ export const BUILTINS = { }, relativedelta: PyRelativeDelta, + + true: true, + false: false, }; diff --git a/addons/web/static/tests/core/py_js/py_interpreter_tests.js b/addons/web/static/tests/core/py_js/py_interpreter_tests.js index d9d3b9c115a..6d795c41375 100644 --- a/addons/web/static/tests/core/py_js/py_interpreter_tests.js +++ b/addons/web/static/tests/core/py_js/py_interpreter_tests.js @@ -145,6 +145,11 @@ QUnit.module("py", {}, () => { } ); + QUnit.test("true and false available in context", (assert) => { + assert.strictEqual(evaluateExpr("true"), true); + assert.strictEqual(evaluateExpr("false"), false); + }); + QUnit.test("throw error if name is not defined", (assert) => { assert.throws(() => evaluateExpr("a")); });