From da043e963539eaef3b32f1912fe56990010c6257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre=20=28lul=29?= Date: Tue, 23 Jan 2024 09:06:17 +0000 Subject: [PATCH] [FIX] spreadsheet: un-escape filter name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: - insert a global filter with double quotes in its name (e.g. my "special" filter) - reference that filter with ODOO.FILTER.VALUE (remember you have to escape the " in the formula with a backslash \ =ODOO.FILTER.VALUE("my \"special\" filter") => the filter is not found closes odoo/odoo#153337 Task: 3697855 X-original-commit: 83826d3546ff584c5ff22021370f572787d032bc Signed-off-by: Rémi Rahir (rar) Signed-off-by: Lucas Lefèvre (lul) --- .../static/src/pivot/pivot_functions.js | 3 ++- .../global_filters/global_filters_model_test.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/addons/spreadsheet/static/src/pivot/pivot_functions.js b/addons/spreadsheet/static/src/pivot/pivot_functions.js index 71933b4336f..789e710ac7e 100644 --- a/addons/spreadsheet/static/src/pivot/pivot_functions.js +++ b/addons/spreadsheet/static/src/pivot/pivot_functions.js @@ -47,7 +47,8 @@ const ODOO_FILTER_VALUE = { args: [arg("filter_name (string)", _t("The label of the filter whose value to return."))], category: "Odoo", compute: function (filterName) { - return this.getters.getFilterDisplayValue(filterName); + const unEscapedFilterName = toString(filterName).replaceAll('\\"', '"'); + return this.getters.getFilterDisplayValue(unEscapedFilterName); }, returns: ["STRING"], }; diff --git a/addons/spreadsheet/static/tests/global_filters/global_filters_model_test.js b/addons/spreadsheet/static/tests/global_filters/global_filters_model_test.js index fe88ca7edbf..5614733ace0 100644 --- a/addons/spreadsheet/static/tests/global_filters/global_filters_model_test.js +++ b/addons/spreadsheet/static/tests/global_filters/global_filters_model_test.js @@ -944,6 +944,21 @@ QUnit.module("spreadsheet > Global filters model", {}, () => { assert.verifySteps(["read_1", "read_2"]); }); + QUnit.test( + "ODOO.FILTER.VALUE with escaped quotes in the filter label", + async function (assert) { + const model = await createModelWithDataSource(); + await addGlobalFilter(model, { + id: "42", + type: "text", + label: 'my "special" filter', + defaultValue: "Jean-Jacques", + }); + setCellContent(model, "A1", '=ODOO.FILTER.VALUE("my \\"special\\" filter")'); + assert.equal(getCellValue(model, "A1"), "Jean-Jacques"); + } + ); + QUnit.test( "ODOO.FILTER.VALUE formulas are updated when filter label is changed", async function (assert) {