Skip to content

Commit

Permalink
[TASK] Fix phpstan checkFunctionArgumentTypes errors in ext:core Html
Browse files Browse the repository at this point in the history
This patch fixes incompatible type usage in function arguments
and is preparatory work for introducing native type hints and
strict mode in all core files.

Resolves: #92267
Releases: master, 10.4
Change-Id: I2bc6a6ee2f97c880dd370cae08b2ac74a988ff1d
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65662
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
  • Loading branch information
alexanderschnitzler authored and ervaude committed Sep 11, 2020
1 parent 9939c79 commit 27593da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions typo3/sysext/core/Classes/Html/HtmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public function splitIntoBlock($tag, $content, $eliminateExtraEndTags = false)
});
$regexStr = '/\\<\\/?(' . implode('|', $tags) . ')(\\s*\\>|\\s[^\\>]*\\>)/si';
$parts = preg_split($regexStr, $content);
if (empty($parts)) {
return [];
}
$newParts = [];
$pointer = strlen($parts[0]);
$buffer = $parts[0];
Expand Down Expand Up @@ -165,6 +168,9 @@ public function splitTags($tag, $content)
});
$regexStr = '/\\<(' . implode('|', $tags) . ')(\\s[^>]*)?\\/?>/si';
$parts = preg_split($regexStr, $content);
if (empty($parts)) {
return [];
}
$pointer = strlen($parts[0]);
$newParts = [];
$newParts[] = $parts[0];
Expand Down Expand Up @@ -267,7 +273,7 @@ public function get_tag_attributes($tag, $deHSC = false)
$name = '';
}
} else {
if ($namekey = preg_replace('/[^[:alnum:]_\\:\\-]/', '', $val)) {
if ($namekey = preg_replace('/[^[:alnum:]_\\:\\-]/', '', $val) ?? '') {
$name = strtolower($namekey);
$attributesMeta[$name] = [];
$attributesMeta[$name]['origTag'] = $namekey;
Expand Down Expand Up @@ -425,7 +431,7 @@ public function HTMLcleaner($content, $tags = [], $keepAll = 0, $hSC = 0, $addCo
}
$firstChar = $tok[0] ?? null;
// It is a tag... (first char is a-z0-9 or /) (fixed 19/01 2004). This also avoids triggering on <?xml..> and <!DOCTYPE..>
if (!$skipTag && preg_match('/[[:alnum:]\\/]/', $firstChar) === 1) {
if (!$skipTag && preg_match('/[[:alnum:]\\/]/', (string)$firstChar) === 1) {
$tagEnd = strpos($tok, '>');
// If there is and end-bracket... tagEnd can't be 0 as the first character can't be a >
if ($tagEnd) {
Expand Down Expand Up @@ -1007,7 +1013,7 @@ public function stripEmptyTags($content, $tagList = '', $treatNonBreakingSpaceAs
$nbspRegex = $treatNonBreakingSpaceAsEmpty ? '|(&nbsp;)' : '';
$finalRegex = sprintf('/<(%s)[^>]*>( %s)*<\/\\1[^>]*>/i', $tagRegEx, $nbspRegex);
while ($count !== 0) {
$content = preg_replace($finalRegex, '', $content, -1, $count);
$content = preg_replace($finalRegex, '', $content, -1, $count) ?? $content;
}
return $content;
}
Expand Down
6 changes: 3 additions & 3 deletions typo3/sysext/core/Classes/Html/RteHtmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function transformTextForPersistence(string $value, array $processingConf
// Transform empty paragraphs into spacing paragraphs
$value = str_replace('<p></p>', '<p>&nbsp;</p>', $value);
// Double any trailing spacing paragraph so that it does not get removed by divideIntoLines()
$value = preg_replace('/<p>&nbsp;<\/p>$/', '<p>&nbsp;</p><p>&nbsp;</p>', $value);
$value = preg_replace('/<p>&nbsp;<\/p>$/', '<p>&nbsp;</p><p>&nbsp;</p>', $value) ?? $value;
$value = $this->TS_transform_db($value);
break;
default:
Expand Down Expand Up @@ -711,9 +711,9 @@ protected function processContentWithinParagraph(string $content, string $fullCo
*/
protected function sanitizeLineBreaksForContentOnly(string $content)
{
$content = preg_replace('/<(hr)(\\s[^>\\/]*)?[[:space:]]*\\/?>/i', LF . '<$1$2/>' . LF, $content);
$content = preg_replace('/<(hr)(\\s[^>\\/]*)?[[:space:]]*\\/?>/i', LF . '<$1$2/>' . LF, $content) ?? $content;
$content = str_replace(LF . LF, LF, $content);
$content = preg_replace('/(^' . LF . ')|(' . LF . '$)/i', '', $content);
$content = preg_replace('/(^' . LF . ')|(' . LF . '$)/i', '', $content) ?? $content;
return $content;
}

Expand Down

0 comments on commit 27593da

Please sign in to comment.