Bug #106402
openCritical error in LocalizationUtility.php when accessing Backend Users in Spanish
0%
Description
In TYPO3 v12.4.28 with PHP 8.4, a critical error occurs in LocalizationUtility.php when accessing the "Usuarios de backend" module with the backend language set to Spanish. The issue seems to be caused by an invalid format specifier in a translation string.
Log output:
[CRITICAL] request="422d3a6447131" component="TYPO3.CMS.Core.Error.ProductionExceptionHandler": Core: Exception handler (WEB: BE): ValueError, code #0, file /var/www/cms_typo3/vendor/typo3/cms-extbase/Classes/Utility/LocalizationUtility.php, line 91: Unknown format specifier "?"
Steps to reproduce
Set the TYPO3 backend language to Spanish.
Go to TYPO3 Backend > Usuarios de backend.
TYPO3 crashes with a ValueError: Unknown format specifier "?".
Expected behavior
Instead of throwing a critical error, the system should handle incorrect placeholders gracefully.
Suggested Fix
Modify LocalizationUtility.php (lines 87-93) to validate placeholders before calling sprintf().
Current code:
if (is_array($arguments) && $arguments !== [] && $value !== null) {
return sprintf($value, ...array_values($arguments)) ?: sprintf(
'Error: could not translate key "%s" with value "%s" and %d argument(s)!',
$key,
$value,
count($arguments)
);
}
Proposed fix:
if (is_array($arguments) && $arguments !== [] && strpos($value, '%') !== false) {
preg_match_all('/%[a-zA-Z]/', $value, $matches);
if (count($matches0) !== count($arguments)) {
return sprintf('Error: could not translate key "%s" with value "%s" and %d argument(s)!', $key, $value, count($arguments));
}
}
Files
Updated by Josué Gutiérrez Carrillo about 1 month ago
- Description updated (diff)
Updated by Georg Ringer about 1 month ago
- File Bildschirmfoto 2025-03-20 um 15.27.54.png Bildschirmfoto 2025-03-20 um 15.27.54.png added
- Status changed from New to Needs Feedback
thanks for creating the issue. I couldn't reproduce that on main or 12.4.28 using latest downloads of spanish backend
can you check which string is the culprit and maybe also test on a clean system?
Updated by Gerrit Code Review about 1 month ago
- Status changed from Needs Feedback to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/88661
Updated by Garvin Hicking about 1 month ago
I would also love to understand which exact language key is causing the trouble here so that we might fix that on translation servers.
I've created the linked patch with an alternate approach to your idea, by working with catching the possible two types of exceptions that sprintf() may throw. If you would be able to check out that patch, that would be great.
Thanks for bringing this up, this is very helpful!
Updated by Josué Gutiérrez Carrillo about 1 month ago
Garvin Hicking wrote in #note-4:
I would also love to understand which exact language key is causing the trouble here so that we might fix that on translation servers.
I've created the linked patch with an alternate approach to your idea, by working with catching the possible two types of exceptions that sprintf() may throw. If you would be able to check out that patch, that would be great.
Thanks for bringing this up, this is very helpful!
Hi Garvin,
Thanks a lot for the quick fix! It’s working perfectly now. I hope it gets approved smoothly, and I’ll be looking forward to the next update.
Best regards!
Updated by Garvin Hicking 3 days ago
- Related to Task #102045: The LocalizationUtility should handle ValueError Exceptions thrown by sprintf added