From 83152d0bf2c14ba2f55bccb6dc7a97aa30c975be Mon Sep 17 00:00:00 2001 From: "Adrien Minne (adrm)" Date: Thu, 17 Aug 2023 09:24:57 +0000 Subject: [PATCH] [FIX] web: sprintf named placeholders regex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function `sprintf` can use a dictionnary as second argument along with named placeholders with the syntax `sprintf("%(argName)s", dict)`. But the regex was wrong, making the first parenthesis optional and allowing `sprintf("%argName)s", dict)` as a valid syntax. closes odoo/odoo#132166 Signed-off-by: Lucas Lefèvre (lul) --- addons/web/static/src/core/utils/strings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/static/src/core/utils/strings.js b/addons/web/static/src/core/utils/strings.js index 093abe21101..20699dcd805 100644 --- a/addons/web/static/src/core/utils/strings.js +++ b/addons/web/static/src/core/utils/strings.js @@ -140,7 +140,7 @@ export function intersperse(str, indices, separator = "") { export function sprintf(s, ...values) { if (values.length === 1 && Object.prototype.toString.call(values[0]) === "[object Object]") { const valuesDict = values[0]; - s = s.replace(/%\(?([^)]+)\)s/g, (match, value) => valuesDict[value]); + s = s.replace(/%\(([^)]+)\)s/g, (match, value) => valuesDict[value]); } else if (values.length > 0) { s = s.replace(/%s/g, () => values.shift()); }