Project

General

Profile

Actions

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.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Localization
Target version:
-
Start date:
2021-01-22
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

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

local_history.patch (1.79 KB) local_history.patch Dieter Porth, 2021-01-22 11:11

Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #98924: Harden LocalizationUtility with argumentsClosed2022-10-26

Actions
Related to TYPO3 Core - Task #96473: Allow ServerRequestInterface in ext:fluidClosed2022-01-06

Actions
Actions #1

Updated by Dieter Porth almost 4 years ago

  • 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));
        }

Actions #2

Updated by Riccardo De Contardi over 3 years ago

  • Category set to Localization
Actions #3

Updated by Benni Mack 4 months ago

  • Related to Bug #98924: Harden LocalizationUtility with arguments added
Actions #4

Updated by Benni Mack 4 months ago

  • Related to Task #96473: Allow ServerRequestInterface in ext:fluid added
Actions #5

Updated by Benni Mack 4 months ago

  • 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!

Actions

Also available in: Atom PDF