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 6dd1083 commit f8a2f66
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\DB;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\FlashMessages;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Registry;
Expand All @@ -38,6 +39,7 @@
use Psr\Http\Server\RequestHandlerInterface;

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 @@ -194,7 +196,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 @@ -214,6 +215,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 f8a2f66

Please sign in to comment.