From b9c2a3b0adb7f448eb95c92a70be7794265af632 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 2 May 2010 01:07:35 -0700 Subject: [PATCH] Make the Date macro handle leading and trailing whitespace. Fixes bug #11542. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Macro/D_date.pm | 4 ++++ t/Macro/D_date.t | 16 ++++++++++------ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 490af180f..18cc7c2e8 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -12,6 +12,7 @@ - added: CHI cache driver - added #11498: Gallery: Automatically adjust orientation of images based on EXIF data - fixed #11547: Default Inbox View Template Delete buttton failure + - fixed #11542: Date macro can pass in epoch values that do not pass regex checks 7.9.3 - added #11477: No synopsis in asset now means no synopsis in search index diff --git a/lib/WebGUI/Macro/D_date.pm b/lib/WebGUI/Macro/D_date.pm index 317acb236..87b9c9b0b 100644 --- a/lib/WebGUI/Macro/D_date.pm +++ b/lib/WebGUI/Macro/D_date.pm @@ -42,6 +42,10 @@ sub process { if (! defined $time) { $time = time(); } + else { + $time =~ s/^\s+//; + $time =~ s/\s+$//; + } my $temp = $session->datetime->epochToHuman($time, $_[0]); return $temp; } diff --git a/t/Macro/D_date.t b/t/Macro/D_date.t index d6a857975..7eb07cc94 100644 --- a/t/Macro/D_date.t +++ b/t/Macro/D_date.t @@ -8,7 +8,6 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- use FindBin; use strict; use lib "$FindBin::Bin/../lib"; @@ -17,9 +16,9 @@ use WebGUI::Test; use WebGUI::Session; use WebGUI::Macro::D_date; use Data::Dumper; -# ---- END DO NOT EDIT ---- -use Test::More; # increment this value for each test you create +use Test::More; +use Test::Exception; my $wgbday = WebGUI::Test->webguiBirthday; @@ -34,7 +33,7 @@ my @testSets = ( }, ); -my $numTests = scalar @testSets + 2; +my $numTests = scalar @testSets + 4; plan tests => $numTests; @@ -62,5 +61,10 @@ is($output, $session->datetime->epochToHuman($time1), 'checking default time and ##Checking for edge case, time=0 is WebGUI::Macro::D_date::process($session, '', 0), -'12/31/1969 6:00 pm', -'...checking for handling time=0'; + '12/31/1969 6:00 pm', + '...checking for handling time=0'; + +lives_ok { WebGUI::Macro::D_date::process($session, '', ' 0') } + 'handles leading whitespace okay'; +lives_ok { WebGUI::Macro::D_date::process($session, '', '0 ') } + 'handles trailing whitespace okay';