Skip to content

Commit

Permalink
Fix: #4898 - requesting a non-existing surname breaks the individual …
Browse files Browse the repository at this point in the history
…list
  • Loading branch information
fisharebest committed Nov 5, 2023
1 parent 1c14fbd commit bc8aea9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/Module/IndividualListModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Contracts\UserInterface;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\FlashMessages;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Registry;
Expand All @@ -40,6 +41,7 @@

use function app;
use function array_filter;
use function array_key_exists;
use function array_keys;
use function array_map;
use function array_merge;
Expand Down Expand Up @@ -198,7 +200,6 @@ public function handle(ServerRequestInterface $request): ResponseInterface
->redirectUrl($this->listUrl($tree, $params), StatusCodeInterface::STATUS_MOVED_PERMANENTLY);
}


// Make sure parameters are consistent with each other.
if ($show_all_firstnames === 'yes') {
$falpha = '';
Expand All @@ -218,6 +219,15 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$all_surnames = $this->allSurnames($surname_data);
$surname_initials = $this->surnameInitials($surname_data);

// We've requested a surname that doesn't currently exist.
if (!array_key_exists($surname, $all_surns)) {
$message = I18N::translate('There are no individuals with the surname “%s“', e($surname));
FlashMessages::addMessage($message);

return Registry::responseFactory()
->redirectUrl($this->listUrl($tree));
}

// Make sure selections are consistent.
// i.e. can’t specify show_all and surname at the same time.
if ($show_all === 'yes') {
Expand Down

0 comments on commit bc8aea9

Please sign in to comment.