Commit d8e25e2c authored by Benni Mack's avatar Benni Mack
Browse files

[BUGFIX] Ensure config.spamProtectEmailAddresses = ascii works for external URLs

When having a page of type "External URL", set to
an email address, and config.spamProtectEmailAddresses = ascii
set in TypoScript, the encoding now works properly.

Resolves: #87787
Releases: main, 11.5
Change-Id: I15563f08a8a0007dc292f5d7e1a311e38a55db26
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72914

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 83daec59
......@@ -54,6 +54,7 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
*/
public function build(array &$linkDetails, string $linkText, string $target, array $conf): LinkResultInterface
{
$linkResultType = LinkService::TYPE_PAGE;
$tsfe = $this->getTypoScriptFrontendController();
if (empty($linkDetails['pageuid']) || $linkDetails['pageuid'] === 'current') {
// If no id is given
......@@ -226,6 +227,10 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
$this->contentObjectRenderer->typoLink($linkText, $conf);
$target = $this->contentObjectRenderer->lastTypoLinkTarget;
$url = $this->contentObjectRenderer->lastTypoLinkUrl;
// If the page external URL is resolved into a URL or email, this should be taken into account when compiling the final link result object
if ($this->contentObjectRenderer->lastTypoLinkResult) {
$linkResultType = $this->contentObjectRenderer->lastTypoLinkResult->getType();
}
if (empty($url)) {
throw new UnableToLinkException('Link to external page "' . $page['uid'] . '" does not have a proper target URL, so "' . $linkText . '" was not linked.', 1551621999, null, $linkText);
}
......@@ -282,7 +287,7 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
// Setting title if blank value to link
$linkText = $this->parseFallbackLinkTextIfLinkTextIsEmpty($linkText, $page['title']);
$result = new LinkResult(LinkService::TYPE_PAGE, $url);
$result = new LinkResult($linkResultType, $url);
return $result
->withLinkConfiguration($conf)
->withTarget($target)
......
......@@ -164,6 +164,8 @@ entities:
- self: {id: 2700, title: 'Announcements & News', type: *pageMount, mount: 7100, slug: '/news'}
- self: {id: 2800, title: 'What is a blog on Wikipedia ', type: *pageExternalUrl, url: 'https://en.wikipedia.org/wiki/Blog', slug: '/what-is-a-blog', target: 'a_new_tab' }
- self: {id: 2900, title: 'What is Wikipedia in a separate window ', type: *pageExternalUrl, url: 'https://en.wikipedia.org/', slug: '/wikipedia' }
children:
- self: {id: 2910, title: 'Contact wikipedia', type: *pageExternalUrl, url: 'mailto:you-never-get-an-answer', nav_hide: 1, slug: '/wikipedia/send-an-email' }
- self: {id: 2930, title: 'ACME Inc', type: *pageShortcut, shortcut: 1000, slug: '/acme'}
- self: {id: 3000, title: 'ACME Archive', root: true, slug: '/'}
languageVariants:
......
......@@ -21,8 +21,10 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\Fixtures\LinkHandlingController;
use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\ArrayValueInstruction;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\TypoScriptInstruction;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext;
......@@ -670,6 +672,38 @@ class SlugLinkGeneratorTest extends AbstractTestCase
self::assertSame($expectation, (string)$response->getBody());
}
/**
* @test
*/
public function linkIsGeneratedForExternalUrlOfEmailWithSpamProtectedEmailAddressesSetToAscii(): void
{
$response = $this->executeFrontendSubRequest(
(new InternalRequest('https://blog.acme.com/'))
->withPageId(2100)
->withInstructions([
(new TypoScriptInstruction(TemplateService::class))
->withTypoScript([
'config.' => [
'spamProtectEmailAddresses' => 'ascii',
],
]),
(new ArrayValueInstruction(LinkHandlingController::class))
->withArray([
'10' => 'TEXT',
'10.' => [
'typolink.' => [
'parameter' => 2910,
],
],
]),
]),
);
$result = (string)$response->getBody();
$expectation = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#121;&#111;&#117;&#45;&#110;&#101;&#118;&#101;&#114;&#45;&#103;&#101;&#116;&#45;&#97;&#110;&#45;&#97;&#110;&#115;&#119;&#101;&#114;">Contact wikipedia</a>';
self::assertSame($expectation, $result);
}
/**
* @return array
*/
......
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