Commit 883b98ce authored by Thomas Hohn's avatar Thomas Hohn Committed by Stefan Bürk
Browse files

[BUGFIX] Make http_makelinks more fault tolerant

Ensure that call to parse_url in http_makelinks handles
parsing error correctly.

Resolves: #99653
Releases: main, 11.5
Change-Id: I056d1737a27607f5f2ae9832a5ee495ccf7494c8
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77513


Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
parent 2b898bc9
......@@ -3564,36 +3564,41 @@ class ContentObjectRenderer implements LoggerAwareInterface
$textstr = $textpieces[0];
for ($i = 1; $i < $pieces; $i++) {
$len = strcspn($textpieces[$i], chr(32) . "\t" . CRLF);
if (trim(substr($textstr, -1)) === '' && $len) {
$lastChar = substr($textpieces[$i], $len - 1, 1);
if (!preg_match('/[A-Za-z0-9\\/#_-]/', $lastChar)) {
$len--;
}
// Included '\/' 3/12
$parts[0] = substr($textpieces[$i], 0, $len);
$parts[1] = substr($textpieces[$i], $len);
$keep = $conf['keep'] ?? '';
$linkParts = parse_url($scheme . $parts[0]);
$linktxt = '';
if (str_contains($keep, 'scheme')) {
$linktxt = $scheme;
}
$linktxt .= $linkParts['host'];
if (str_contains($keep, 'path')) {
$linktxt .= ($linkParts['path'] ?? '');
// Added $linkParts['query'] 3/12
if (str_contains($keep, 'query') && $linkParts['query']) {
$linktxt .= '?' . $linkParts['query'];
} elseif (($linkParts['path'] ?? '') === '/') {
$linktxt = substr($linktxt, 0, -1);
}
}
$typolinkConfiguration = $conf;
$typolinkConfiguration['parameter'] = $scheme . $parts[0];
$textstr .= $this->typoLink($linktxt, $typolinkConfiguration) . $parts[1];
} else {
if (!(trim(substr($textstr, -1)) === '' && $len)) {
$textstr .= $scheme . $textpieces[$i];
continue;
}
$lastChar = substr($textpieces[$i], $len - 1, 1);
if (!preg_match('/[A-Za-z0-9\\/#_-]/', $lastChar)) {
$len--;
}
// Included '\/' 3/12
$parts[0] = substr($textpieces[$i], 0, $len);
$parts[1] = substr($textpieces[$i], $len);
$keep = $conf['keep'] ?? '';
$linkParts = parse_url($scheme . $parts[0]);
// Check if link couldn't be parsed properly
if (!is_array($linkParts)) {
$textstr .= $scheme . $textpieces[$i];
continue;
}
$linktxt = '';
if (str_contains($keep, 'scheme')) {
$linktxt = $scheme;
}
$linktxt .= $linkParts['host'] ?? '';
if (str_contains($keep, 'path')) {
$linktxt .= ($linkParts['path'] ?? '');
// Added $linkParts['query'] 3/12
if (str_contains($keep, 'query') && $linkParts['query']) {
$linktxt .= '?' . $linkParts['query'];
} elseif (($linkParts['path'] ?? '') === '/') {
$linktxt = substr($linktxt, 0, -1);
}
}
$typolinkConfiguration = $conf;
$typolinkConfiguration['parameter'] = $scheme . $parts[0];
$textstr .= $this->typoLink($linktxt, $typolinkConfiguration) . $parts[1];
}
$data = $textstr;
}
......
Supports Markdown
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