From 041e24941181b460dd7ccb2794cbe235fd7310dd Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Wed, 3 Nov 2021 12:15:18 +0000
Subject: [PATCH] Bug 29403: Match the whole string

This patch wraps the constructed regex such that we expect the entire
regex to match and don't allow leading or trailing garbage.
---
 Koha/DateUtils.pm | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm
index ad242b59eb..c4120b8c8f 100644
--- a/Koha/DateUtils.pm
+++ b/Koha/DateUtils.pm
@@ -162,6 +162,10 @@ sub dt_from_string {
     $regex .= $time_re unless ( $date_format eq 'rfc3339' );
     $fallback_re .= $time_re;
 
+    # Ensure we only accept date strings and not other characters.
+    $regex = '^' . $regex . '$';
+    $fallback_re = '^' . $fallback_re . '$';
+
     my %dt_params;
     my $ampm;
     if ( $date_string =~ $regex ) {
-- 
2.20.1