LP#1189989: (follow-up) ignore invalid thaw date
authorGalen Charlton <gmc@equinoxinitiative.org>
Wed, 2 Aug 2017 15:49:08 +0000 (11:49 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Wed, 2 Aug 2017 15:49:08 +0000 (11:49 -0400)
This patch ensures that the specified thaw date is valid,
as otherwise specifying a thaw date of "13/08/2017" (when,
at present, only dates of the form mm/dd/yyyy are accepted)
would result in an Apache internal server error.

If an invalid date is supplied, the thaw date is ignored, meaning
that the hold request will be placed as suspended but will not
automatically reactivate.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm

index 9c5f14d..765ecf3 100644 (file)
@@ -12,6 +12,7 @@ use Digest::MD5 qw(md5_hex);
 use Data::Dumper;
 $Data::Dumper::Indent = 0;
 use DateTime;
+use DateTime::Format::ISO8601;
 my $U = 'OpenILS::Application::AppUtils';
 
 sub prepare_extended_user_info {
@@ -1040,7 +1041,13 @@ sub load_place_hold {
         # We should use a date input type on the forms once it is supported by Firefox.
         # I didn't do that now because it is not available in a general release.
         if ($cgi->param('thaw_date') =~ m:^(\d{2})/(\d{2})/(\d{4})$:){
-            $ctx->{thaw_date} = "$3-$1-$2";
+            eval {
+                my $dt = DateTime::Format::ISO8601->parse_datetime("$3-$1-$2");
+                $ctx->{thaw_date} = $dt->ymd;
+            };
+            if ($@) {
+                $logger->warn("ignoring invalid thaw_date when placing hold request");
+            }
         }
     }