From 56b50e5b0f180efc1460e96a35b09303ab6d7ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Thu, 29 Sep 2016 14:47:28 +0200 Subject: [PATCH] [SIGNED-OFF]Bug 17375: Prevent internal software error when searching patron with invalid birth date To reproduce: - Go to Home > Patron - Expand patron search (click on + at the left of the search button) - In drop down 'Search fields', select 'Date of birth' - Enter a valid date (e.g. 11.02.1995 if syspref 'dateformat' is set to dmydot) Result: Search works OK - Enter an invalid date, e.g. 11.02 or abcd... Result: Internal server error - Do a patron search with many results - Use filter on results screen, select 'Date of birth' as search field and enter an invalid date to search (e.g. 'a') Result: Endless message 'Processing' To test: - Apply patch - Repeat steps above - In both cases, you should get "No results" Signed-off-by: Hector Castro Both cases works as advertised --- members/member.pl | 2 +- svc/members/search | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/members/member.pl b/members/member.pl index 5a8639d..4f0ea22 100755 --- a/members/member.pl +++ b/members/member.pl @@ -65,7 +65,7 @@ if ( $quicksearch and $searchmember ) { my $searchfieldstype = $input->param('searchfieldstype') || 'standard'; if ( $searchfieldstype eq "dateofbirth" ) { - $searchmember = output_pref({dt => dt_from_string($searchmember), dateformat => 'iso', dateonly => 1}); + $searchmember = eval { output_pref({dt => dt_from_string($searchmember), dateformat => 'iso', dateonly => 1}); }; } $template->param( 'alphabet' => C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ); diff --git a/svc/members/search b/svc/members/search index 2599519..9980263 100755 --- a/svc/members/search +++ b/svc/members/search @@ -48,7 +48,11 @@ my $has_permission = $input->param('has_permission'); my $selection_type = $input->param('selection_type'); if ( $searchfieldstype eq "dateofbirth" ) { - $searchmember = output_pref({dt => dt_from_string($searchmember), dateformat => 'iso', dateonly => 1}); + $searchmember = eval { output_pref({dt => dt_from_string($searchmember), dateformat => 'iso', dateonly => 1}); }; + # Prevent display of all dates if date was not valid + unless ($searchmember ) { + $searchmember = "1000-01-01"; + } } # variable information for DataTables (id) -- 1.7.10.4