Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Ensure that relative target link can be set in EXT:redirects
The TYPO3 system extension `redirects` now fully supports the setting of relative links as the `target` URL, which is a documented feature. Previously, an issue arose when attempting to use path links with leading slashes as URLs. This issue has been addressed in #101083, marking the initial step toward resolving the problem of relative target links. Additionally, the fix now allows for linking to arbitrary resources, even those that do not currently exist in the File Abstraction Layer (FAL). The class `TYPO3\CMS\Core\LinkHandling\LegacyLinkNotationConverter` has been changed to limit the handling of arbitrary resources to the smallest scope to reuse existing code and to use them as `LinkService::TYPE_URL` links. The superflous outer catch block has been removed to remove dead code. In addition, a test for coverage has been added that covers DataHandler and the lower LinkHandling layer. Resolves: #103387 Related: #101083 Releases: main, 12.4 Change-Id: I51cad29e5551824a0ad8d4528aa43cff7e0f9da7 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83444 Reviewed-by: Markus Klein <markus.klein@typo3.org> Tested-by: Markus Klein <markus.klein@typo3.org> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com> Tested-by: Benni Mack <benni@typo3.org> Tested-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Stefan Bürk <stefan@buerk.tech>
- Loading branch information
Showing
7 changed files
with
208 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+1.36 KB
.../core/Tests/Functional/LinkHandling/Fixtures/fileadmin/some/path/typo3-logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 94 additions & 0 deletions
94
typo3/sysext/core/Tests/Functional/LinkHandling/LegacyLinkNotationConverterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\Core\Tests\Functional\LinkHandling; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use TYPO3\CMS\Core\Core\Environment; | ||
use TYPO3\CMS\Core\LinkHandling\LegacyLinkNotationConverter; | ||
use TYPO3\CMS\Core\LinkHandling\LinkService; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
final class LegacyLinkNotationConverterTest extends FunctionalTestCase | ||
{ | ||
/** | ||
* @var array<string, non-empty-string> | ||
*/ | ||
protected array $pathsToProvideInTestInstance = [ | ||
'typo3/sysext/core/Tests/Functional/LinkHandling/Fixtures/fileadmin/' => 'fileadmin/', | ||
]; | ||
|
||
protected function tearDown(): void | ||
{ | ||
GeneralUtility::rmdir(Environment::getPublicPath() . '/fileadmin', true); | ||
mkdir(Environment::getPublicPath() . '/fileadmin'); | ||
GeneralUtility::rmdir(Environment::getPublicPath() . '/typo3temp/assets/_processed_', true); | ||
parent::tearDown(); | ||
} | ||
|
||
public static function resolveReturnExpectedResultDataProvider(): \Generator | ||
{ | ||
yield '#1 linkParameter looking like absolute path without tailing slash and not existing (file and folder) in FAL resolves to type URL' => [ | ||
'linkParameter' => '/path/not/existing/in/fal', | ||
'expected' => [ | ||
'type' => LinkService::TYPE_URL, | ||
'url' => '/path/not/existing/in/fal', | ||
], | ||
]; | ||
yield '#2 linkParameter looking like absolute path with tailing slash and not existing (file and folder) in FAL resolves to type URL' => [ | ||
'linkParameter' => '/path/not/existing/in/fal/', | ||
'expected' => [ | ||
'type' => LinkService::TYPE_URL, | ||
'url' => '/path/not/existing/in/fal/', | ||
], | ||
]; | ||
yield '#3 linkParameter looking like absolute path without tailing slash and existing folder in FAL resolves to type URL' => [ | ||
'linkParameter' => '/fileadmin/some/path', | ||
'expected' => [ | ||
'type' => LinkService::TYPE_URL, | ||
'url' => '/fileadmin/some/path', | ||
], | ||
]; | ||
yield '#4 linkParameter looking like absolute path with tailing slash and existing folder in FAL resolves to type URL' => [ | ||
'linkParameter' => '/fileadmin/some/path/', | ||
'expected' => [ | ||
'type' => LinkService::TYPE_URL, | ||
'url' => '/fileadmin/some/path/', | ||
], | ||
]; | ||
yield '#5 linkParameter for existing file returns type URL on fallback storage' => [ | ||
'linkParameter' => '/fileadmin/some/path/typo3-logo.png', | ||
'expected' => [ | ||
'type' => LinkService::TYPE_URL, | ||
'url' => '/fileadmin/some/path/typo3-logo.png', | ||
], | ||
]; | ||
} | ||
|
||
#[DataProvider('resolveReturnExpectedResultDataProvider')] | ||
#[Test] | ||
public function resolveReturnsExpectedResult( | ||
string $linkParameter, | ||
array $expected, | ||
): void { | ||
$subject = GeneralUtility::makeInstance(LegacyLinkNotationConverter::class); | ||
|
||
self::assertSame($expected, $subject->resolve($linkParameter)); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
typo3/sysext/core/Tests/Functional/LinkHandling/LinkServiceTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\Core\Tests\Functional\LinkHandling; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use TYPO3\CMS\Core\Core\Environment; | ||
use TYPO3\CMS\Core\LinkHandling\LinkService; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
final class LinkServiceTest extends FunctionalTestCase | ||
{ | ||
/** | ||
* @var array<string, non-empty-string> | ||
*/ | ||
protected array $pathsToProvideInTestInstance = [ | ||
'typo3/sysext/core/Tests/Functional/LinkHandling/Fixtures/fileadmin/' => 'fileadmin/', | ||
]; | ||
|
||
protected function tearDown(): void | ||
{ | ||
GeneralUtility::rmdir(Environment::getPublicPath() . '/fileadmin', true); | ||
mkdir(Environment::getPublicPath() . '/fileadmin'); | ||
GeneralUtility::rmdir(Environment::getPublicPath() . '/typo3temp/assets/_processed_', true); | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* @return array<string, array<string, mixed>> | ||
*/ | ||
public static function resolveReturnExpectedResultDataProvider(): array | ||
{ | ||
// Reuse DataProviders of concrete link-type testcases | ||
return [ | ||
...LegacyLinkNotationConverterTest::resolveReturnExpectedResultDataProvider(), | ||
// @todo Add tests for other link types and combine them here for the link service level | ||
]; | ||
} | ||
|
||
#[DataProvider('resolveReturnExpectedResultDataProvider')] | ||
#[Test] | ||
public function resolveReturnsExpectedResult( | ||
string $linkParameter, | ||
array $expected, | ||
): void { | ||
$subject = GeneralUtility::makeInstance(LinkService::class); | ||
|
||
self::assertSame($expected, $subject->resolve($linkParameter)); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...directs/Tests/Functional/Service/Fixtures/AssertionDataSets/RelativeTargetDataHandler.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"pages", | ||
,"uid","pid","title","slug","l10n_parent","l10n_source","sys_language_uid","doktype" | ||
,1,0,"Root 1","/",0,0,0,1 | ||
"sys_redirect", | ||
,"uid","pid","deleted","disabled","source_host","source_path","target" | ||
,1,1,0,0,"*","/test-redirect-1/","/relative-target/" |
3 changes: 3 additions & 0 deletions
3
typo3/sysext/redirects/Tests/Functional/Service/Fixtures/RelativeTargetDataHandler.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"pages",,,,,,, | ||
,"uid","pid","title","slug","l10n_parent","l10n_source","sys_language_uid","doktype" | ||
,1,0,"Root 1","/",0,0,0,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters