Commit 6f37527f authored by Oliver Klee's avatar Oliver Klee Committed by Georg Ringer
Browse files

[BUGFIX] Avoid calling string functions with non-strings in GU

This helps avoid breakage when GeneralUtility will switch to
strict mode.

Resolves: #97579
Relates: #97578
Releases: main, 11.5
Change-Id: I813075a74805b72781a493278e45aa1e9a1e2cc2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74573

Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent 05007288
...@@ -959,8 +959,11 @@ class GeneralUtility ...@@ -959,8 +959,11 @@ class GeneralUtility
if (is_array($AVal)) { if (is_array($AVal)) {
$str = self::implodeArrayForUrl($thisKeyName, $AVal, $str, $skipBlank, $rawurlencodeParamName); $str = self::implodeArrayForUrl($thisKeyName, $AVal, $str, $skipBlank, $rawurlencodeParamName);
} else { } else {
if (!$skipBlank || (string)$AVal !== '') { $stringValue = (string)$AVal;
$str .= '&' . ($rawurlencodeParamName ? rawurlencode($thisKeyName) : $thisKeyName) . '=' . rawurlencode($AVal); if (!$skipBlank || $stringValue !== '') {
$parameterName = $rawurlencodeParamName ? rawurlencode($thisKeyName) : $thisKeyName;
$parameterValue = rawurlencode($stringValue);
$str .= '&' . $parameterName . '=' . $parameterValue;
} }
} }
} }
...@@ -1250,7 +1253,7 @@ class GeneralUtility ...@@ -1250,7 +1253,7 @@ class GeneralUtility
// Traverse the input array // Traverse the input array
foreach ($array as $k => $v) { foreach ($array as $k => $v) {
$attr = ''; $attr = '';
$tagName = $k; $tagName = (string)$k;
// Construct the tag name. // Construct the tag name.
// Use tag based on grand-parent + parent tag name // Use tag based on grand-parent + parent tag name
if (isset($stackData['grandParentTagName'], $stackData['parentTagName'], $options['grandParentTagMap'][$stackData['grandParentTagName'] . '/' . $stackData['parentTagName']])) { if (isset($stackData['grandParentTagName'], $stackData['parentTagName'], $options['grandParentTagMap'][$stackData['grandParentTagName'] . '/' . $stackData['parentTagName']])) {
...@@ -1309,28 +1312,29 @@ class GeneralUtility ...@@ -1309,28 +1312,29 @@ class GeneralUtility
$attr .= ' type="array"'; $attr .= ' type="array"';
} }
} else { } else {
$stringValue = (string)$v;
// Just a value: // Just a value:
// Look for binary chars: // Look for binary chars:
$vLen = strlen((string)$v); $vLen = strlen($stringValue);
// Go for base64 encoding if the initial segment NOT matching any binary char has the same length as the whole string! // Go for base64 encoding if the initial segment NOT matching any binary char has the same length as the whole string!
if ($vLen && strcspn($v, $binaryChars) != $vLen) { if ($vLen && strcspn($stringValue, $binaryChars) != $vLen) {
// If the value contained binary chars then we base64-encode it and set an attribute to notify this situation: // If the value contained binary chars then we base64-encode it and set an attribute to notify this situation:
$content = $nl . chunk_split(base64_encode($v)); $content = $nl . chunk_split(base64_encode($stringValue));
$attr .= ' base64="1"'; $attr .= ' base64="1"';
} else { } else {
// Otherwise, just htmlspecialchar the stuff: // Otherwise, just htmlspecialchar the stuff:
$content = htmlspecialchars((string)$v); $content = htmlspecialchars($stringValue);
$dType = gettype($v); $dType = gettype($v);
if ($dType === 'string') { if ($dType === 'string') {
if (isset($options['useCDATA']) && $options['useCDATA'] && $content != $v) { if (isset($options['useCDATA']) && $options['useCDATA'] && $content != $stringValue) {
$content = '<![CDATA[' . $v . ']]>'; $content = '<![CDATA[' . $stringValue . ']]>';
} }
} elseif (!($options['disableTypeAttrib'] ?? false)) { } elseif (!($options['disableTypeAttrib'] ?? false)) {
$attr .= ' type="' . $dType . '"'; $attr .= ' type="' . $dType . '"';
} }
} }
} }
if ((string)$tagName !== '') { if ($tagName !== '') {
// Add the element to the output string: // Add the element to the output string:
$output .= ($spaceInd >= 0 ? str_pad('', ($level + 1) * $indentN, $indentChar) : '') $output .= ($spaceInd >= 0 ? str_pad('', ($level + 1) * $indentN, $indentChar) : '')
. '<' . $NSprefix . $tagName . $attr . '>' . $content . '</' . $NSprefix . $tagName . '>' . $nl; . '<' . $NSprefix . $tagName . $attr . '>' . $content . '</' . $NSprefix . $tagName . '>' . $nl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment