[FIX] web: sprintf named placeholders regex

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) <lul@odoo.com>
This commit is contained in:
Adrien Minne (adrm)
2023-08-22 09:49:40 +02:00
parent fe54b6eb21
commit 83152d0bf2
+1 -1
View File
@@ -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());
}