Project

General

Profile

Actions

Bug #106402

open

Critical error in LocalizationUtility.php when accessing Backend Users in Spanish

Added by Josué Gutiérrez Carrillo about 1 month ago. Updated about 1 month ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
Localization
Target version:
Start date:
2025-03-20
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
8.4
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

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


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Task #102045: The LocalizationUtility should handle ValueError Exceptions thrown by sprintfClosed2023-09-27

Actions
Actions #1

Updated by Josué Gutiérrez Carrillo about 1 month ago

  • Description updated (diff)
Actions #2

Updated by Georg Ringer about 1 month ago

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?

Actions #3

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

Actions #4

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!

Actions #5

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!

Actions #6

Updated by Garvin Hicking 3 days ago

  • Related to Task #102045: The LocalizationUtility should handle ValueError Exceptions thrown by sprintf added
Actions

Also available in: Atom PDF