From 48f9687025b74cbd3ba5bb3b0f2219a6555d432e Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Wed, 8 Dec 2010 14:32:20 -0600 Subject: [PATCH] fix 11984 No JS allows invalid dates in Event --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Event.pm | 11 ++++++++++- lib/WebGUI/i18n/English/Asset_Event.pm | 12 ++++++++++++ t/Asset/Event.t | 10 +++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 9f91b7243..c056ae177 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,6 +1,7 @@ 7.10.7 - added #11968: use the language override in the registration form (Jukka Raimovaara / Mentalhouse Oy) - Changed Carousel to use TinyMCE with WebGUI plugins + - fixed #11984: No JS allows invalid dates in Event asset 7.10.6 - fixed #11974: Toolbar icons unclickable in Webkit using HTML5 diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index 1aac333c8..9d460f7a9 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -1333,8 +1333,17 @@ sub processPropertiesFromFormPost { ### Verify the form was filled out correctly... my @errors; - # If the start date is after the end date my $i18n = WebGUI::International->new($session, 'Asset_Event'); + + # Verify we got valid dates + if ( !eval{ $self->getDateTimeStart; 1 } ) { + push @errors, $i18n->get('invalid start date'); + } + if ( !eval{ $self->getDateTimeEnd; 1 } ) { + push @errors, $i18n->get('invalid end date'); + } + + # If the start date is after the end date if ($self->get("startDate") gt $self->get("endDate")) { push @errors, $i18n->get("The event end date must be after the event start date."); } diff --git a/lib/WebGUI/i18n/English/Asset_Event.pm b/lib/WebGUI/i18n/English/Asset_Event.pm index 0c4e7da64..50862cb7d 100644 --- a/lib/WebGUI/i18n/English/Asset_Event.pm +++ b/lib/WebGUI/i18n/English/Asset_Event.pm @@ -821,6 +821,18 @@ be useful, others may not.|, context => 'follows a select list with ordinals, first, second, etc. To form the phrase, First week on, Second week on', }, + 'invalid start date' => { + message => 'Invalid start date. Please enter a valid date in the form "YYYY-MM-DD"', + lastUpdated => 0, + context => 'An error when we cant parse the date they give us', + }, + + 'invalid end date' => { + message => 'Invalid end date. Please enter a valid date in the form "YYYY-MM-DD"', + lastUpdated => 0, + context => 'An error when we cant parse the date they give us', + }, + }; 1; diff --git a/t/Asset/Event.t b/t/Asset/Event.t index ddafe0e8b..bfa545f74 100644 --- a/t/Asset/Event.t +++ b/t/Asset/Event.t @@ -19,7 +19,7 @@ use WebGUI::Asset::Event; use Test::More; # increment this value for each test you create use Test::Deep; -plan tests => 23; +plan tests => 25; my $session = WebGUI::Test->session; @@ -144,6 +144,14 @@ is ($event7->get('startDate'), '2000-09-01', 'startDate bumped by 1 day'); is ($event7->get('endTime'), '00:00:00', 'endTime set to 00:00:00 if the hour is more than 23'); is ($event7->get('endDate'), '2000-09-02', 'endDate bumped by 1 day'); +############################################################################# +# Valid dates +$session->request->setup_body({ startDate => '0000-00-01', endDate => '1000-00-01' }); +my $event = $cal->addChild({ className => 'WebGUI::Asset::Event' }, undef, time()+10); +my $output = $event->processPropertiesFromFormPost; +is( ref $output, 'ARRAY', 'ppffp returns error array' ); +is( scalar @$output, 2, 'has two errors' ); + ####################################### # # duplicate