From f52b76913213d1b98df84efec36b0d89b1d97e20 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 11 Mar 2020 16:20:36 +0000 Subject: [PATCH] Bug 24850: Add tests for invalid RFC3339 dates We should die on invalidly formatted dates being passed. This patch adds such a test case. --- t/DateUtils.t | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/t/DateUtils.t b/t/DateUtils.t index dc1b4210fb..ab8fc1a03d 100755 --- a/t/DateUtils.t +++ b/t/DateUtils.t @@ -4,7 +4,7 @@ use DateTime::TimeZone; use C4::Context; -use Test::More tests => 72; +use Test::More tests => 73; use Test::MockModule; use Test::Warn; @@ -137,6 +137,13 @@ cmp_ok( $dt0->epoch(), 'eq', '1325462399', 'dt_from_string handles seconds with $dt0 = dt_from_string( '2012-01-01T23:59:59.999+02:00', 'rfc3339' ); cmp_ok( $dt0->epoch(), 'eq', '1325455199', 'dt_from_string handles seconds with 3 decimal places and a timezone' ); +try { + $dt0 = dt_from_string( '2012-01-01T23:59:59.999Z+02:00', 'rfc3339' ); +} +catch { + like( $_, qr/.*does not match the date format \(rfc3339\).*/, 'dt_from_string should die when passed a bad date string' ); +}; + # Return undef if passed mysql 0 dates $dt0 = dt_from_string( '0000-00-00', 'iso' ); is( $dt0, undef, "undefined returned for 0 iso date" ); -- 2.20.1