Fix protection for sprintf on bad % specifier

This commit is contained in:
ldestailleur 2025-04-03 21:00:00 +02:00
parent 94703556eb
commit 080fdacf1f

View file

@ -801,7 +801,9 @@ class Translate
}
}
if (!preg_match('/^Format/', $key)) {
$str = preg_replace('/([^%])%([^%0sdmYIMpHSBb])/', '\1__percent_with_bad_specifier__\2', $str);
if (strpos($key, 'Format') !== 0) {
try {
// @phan-suppress-next-line PhanPluginPrintfVariableFormatString
$str = sprintf($str, $param1, $param2, $param3, $param4, $param5); // Replace %s and %d except for FormatXXX strings.
@ -811,6 +813,8 @@ class Translate
}
}
$str = str_replace('__percent_with_bad_specifier__', '%', $str);
// Remove dangerous sequence we should never have. Not needed into a translated response.
// %27 is entity code for ' and is replaced by browser automatically when translation is inside a javascript code called by a click like on a href link.
$str = str_replace(array('%27', '&#39'), '', $str);