diff --git a/src/Http/Controllers/IcsController.php b/src/Http/Controllers/IcsController.php index ba10861..879ae55 100644 --- a/src/Http/Controllers/IcsController.php +++ b/src/Http/Controllers/IcsController.php @@ -3,6 +3,7 @@ namespace TransformStudios\Events\Http\Controllers; use Carbon\CarbonImmutable; +use Carbon\Exceptions\InvalidFormatException; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; @@ -25,8 +26,13 @@ class IcsController extends Controller public function __invoke(Request $request) { + try { + $date = $request->filled('date') ? CarbonImmutable::parse($request->input('date')) : null; + } catch (InvalidFormatException $e) { + abort(404, 'Event not found'); + } + $handle = $request->string('collection', 'events'); - $date = $request->has('date') ? CarbonImmutable::parse($request->get('date')) : null; $eventId = $request->string('event'); $entry = null; diff --git a/tests/Http/Contollers/IcsControllerTest.php b/tests/Http/Contollers/IcsControllerTest.php index d484c15..57a9134 100755 --- a/tests/Http/Contollers/IcsControllerTest.php +++ b/tests/Http/Contollers/IcsControllerTest.php @@ -172,7 +172,7 @@ $this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent()); }); -test('throws404 error when event does not occur on date', function () { +test('throws 404 error when event does not occur on date', function () { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); $this->get(route('statamic.events.ics.show', [ @@ -181,7 +181,7 @@ ]))->assertStatus(404); }); -test('throws404 error when event does not exist', function () { +test('throws 404 error when event does not exist', function () { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); $this->get(route('statamic.events.ics.show', [ @@ -189,3 +189,10 @@ 'event' => 'does-not-exist', ]))->assertStatus(404); }); + +test('throws 404 error when date is invalid', function () { + $this->get(route('statamic.events.ics.show', [ + 'date' => 'not-a-date', + 'event' => 'the-id', + ]))->assertStatus(404); +});