From 796eb0b3167eb77e32401b0a0aaf6d66a0d44ad4 Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Mon, 16 Mar 2009 22:58:19 +0100 Subject: [PATCH] fixed Mojo::Date to not crash on invalid dates --- Changes | 1 + lib/Mojo/Date.pm | 1 + t/mojo/date.t | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 40756d49ff..689132db2f 100644 --- a/Changes +++ b/Changes @@ -10,6 +10,7 @@ This file documents the revision history for Perl extension Mojo. routes internals. - Added Makefile.PL generator. - Support more CGI implementations. + - Fixed Mojo::Date to not crash on invalid dates. (vti) - Fixed tokenizer in MojoX::Routes::Pattern to support "0" values. (Anatoly Sharifulin) - Fixed parsing of "0" in Mojo::Path. (charsbar) diff --git a/lib/Mojo/Date.pm b/lib/Mojo/Date.pm index bb2e82bf85..6ea2a9c210 100644 --- a/lib/Mojo/Date.pm +++ b/lib/Mojo/Date.pm @@ -85,6 +85,7 @@ sub parse { my $epoch; + # Prevent crash eval { $epoch = Time::Local::timegm($second, $minute, $hour, $day, $month, $year); diff --git a/t/mojo/date.t b/t/mojo/date.t index eda5100c22..e5fef51c41 100644 --- a/t/mojo/date.t +++ b/t/mojo/date.t @@ -30,6 +30,6 @@ is($date->epoch, 0); is("$date", 'Thu, 01 Jan 1970 00:00:00 GMT'); is($date->parse('Thu, 01 Jan 1970 00:00:00 GMT')->epoch, 0); -# Wrong time checks +# Bad time checks ok(not defined $date->parse('Mon, 01 Jan 1900 00:00:00')); is($date->epoch, 0);