Issue Bug Closed

#103952utf8-characters can break the debugging-output

Michael Spitz 05/29/24, 13:50 updated 07/09/24, 15:35

Description

I had an UTF-8 String with a special-character at position 76.
The String was not displayed in the debug-output – it was displayed as a multiline empty string.

Example:
debug(‘123456789012345678901234567890123456789012345678901234567890123456789012345ü’);

Possible Solution:
In file vendor/typo3/cms-extbase/Classes/Utility/DebuggerUtility.php in Method renderDump() the String is split into multiple lines (line 106 in T3 v12.4.15):
$lines = str_split($croppedValue, 76);
I tested the multibyte-function instead and for my example it worked:
$lines = mb_str_split($croppedValue, 76);

Maybe other functions in this place should also be tested and replaced with Multibyte-Functions (2000-split and plainText not tested):
if (is_string($value)) {
$croppedValue = mb_strlen($value) > 2000 ? mb_substr($value, 0, 2000) . ‘…’ : $value;
if ($plainText) {
$dump = self::ansiEscapeWrap(‘”’ . implode(PHP_EOL . str_repeat(self::PLAINTEXT_INDENT, $level + 1), mb_str_split($croppedValue, 76)) . ‘”’, ‘33’, $ansiColors) . ‘ (’ . mb_strlen($value) . ‘ chars)’;
} else {
$lines = mb_str_split($croppedValue, 76);
$lines = array_map(static fn(string $line): string => htmlspecialchars($line, ENT_COMPAT), $lines);
$dump = sprintf(‘\’%s\’ (%s chars)’, implode(’
‘ . str_repeat(self::HTML_INDENT, $level + 1), $lines), mb_strlen($value));
}

With this modification, the number of characters is displayed instead of the string-length in bytes (not sure, if this is preferred).

Reviews 3