Bug #93346
closed
LocalizationUtility::translate throws uncaught exception, if the arguments contains an empty array
Added by Dieter Porth almost 4 years ago.
Updated 4 months ago.
Description
$kye = "hallo %s",
$param=[];
sprintf($kye, ...array_values($param));
The code above throws an exception. This exception is uncaught in LocalizationUtility::translate.
I use something like this often. A meaningful exception woul be nice.
$argList = [];
$webTitle = LocalizationUtility::translate(
$item['title'],
'myExtension',
$argList
);
}
Files
- Subject changed from LocalizationUtility::translate throws uncaught exception to LocalizationUtility::translate throws uncaught exception, if the arguments contains an empty array
A similiar php-code to the presente example above will found in the method (Line 123-129)
if (is_array($arguments) && $value !== null) {
// This unrolls arguments from $arguments - instead of calling vsprintf which receives arguments as an array.
// The reason is that only sprintf() will return an error message if the number of arguments does not match
// the number of placeholders in the format string. Whereas, vsprintf would silently return nothing.
return sprintf($value, ...array_values($arguments)) ?: sprintf('Error: could not translate key "%s" with value "%s" and %d argument(s)!', $key, $value, count($arguments));
}
- Category set to Localization
- Related to Bug #98924: Harden LocalizationUtility with arguments added
- Related to Task #96473: Allow ServerRequestInterface in ext:fluid added
- Status changed from New to Closed
Hey Dieter,
thanks for the report. Sorry for not responding earlier but this has been fixed via #98924 in v11 already!
Also available in: Atom
PDF