Trigger 404 for date show action without date

This commit is contained in:
Daniel Siepmann (Codappix) 2024-11-27 08:41:44 +01:00
parent 8eb784cbb3
commit 6bced3c314
SSH key fingerprint: SHA256:nAjx3Dpp8kuAC+S7QXj8BWmqw+KI1Miu+5e40BP3LXA
5 changed files with 42 additions and 1 deletions

View file

@ -70,6 +70,11 @@ abstract class AbstractController extends ActionController
}
}
/**
* Will throw exception to trigger 404.
*
* @return never
*/
protected function trigger404(string $message): void
{
throw new PropagateResponseException(

View file

@ -105,8 +105,12 @@ final class DateController extends AbstractController
}
#[Extbase\IgnoreValidation(['value' => 'date'])]
public function showAction(Date $date): ResponseInterface
public function showAction(?Date $date = null): ResponseInterface
{
if ($date === null) {
$this->trigger404('No date given.');
}
try {
$date->getEvent();
} catch (Throwable) {

View file

@ -33,6 +33,11 @@ Features
The field no longer has a limitation.
The field is now stored as `text` instead of `varchar`.
* Deliver 404 on date show action without a given date.
This previously triggered an TYPO3 Exception.
We now handle the situation and trigger a TYPO3 404.
Fixes
-----

View file

@ -137,6 +137,19 @@ final class DatesTest extends AbstractFrontendTestCase
self::assertStringContainsString('Event 9', $html);
}
#[Test]
public function returns404IfNoDateIsGiven(): void
{
$this->importPHPDataSet(__DIR__ . '/DatesTestFixtures/Returns404IfNoDateIsGiven.php');
$request = new InternalRequest('https://example.com/');
$request = $request->withPageId(1);
$response = $this->executeFrontendSubRequest($request);
self::assertSame(404, $response->getStatusCode());
}
#[Test]
public function returns404IfEventIsHidden(): void
{

View file

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
return [
'tt_content' => [
0 => [
'uid' => '1',
'pid' => '1',
'CType' => 'events_dateshowtest',
'header' => 'Singleview',
],
],
];