Skip Menu |

This queue is for tickets about the Algorithm-Cron CPAN distribution.

Report information
The Basics
Id: 95454
Status: resolved
Priority: 0/
Queue: Algorithm-Cron

People
Owner: Nobody in particular
Requestors: djerius [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.08
Fixed in: 0.09



Subject: leading space in crontab string causes infinite loop
The following code: use Algorithm::Cron; Algorithm::Cron->new( base => q/local/, crontab => q/ 20 23 1 1 */ )->next_time( time ); Causes an infinite loop with the following repeated error: Use of uninitialized value in subroutine entry at [...]/lib/perl5/Algorithm/Cron.pm line 201. Thanks, Diab
On Wed May 07 22:05:09 2014, DJERIUS wrote: Show quoted text
> The following code: > > > use Algorithm::Cron; > Algorithm::Cron->new( base => q/local/, > crontab => q/ 20 23 1 1 */ )->next_time( time );
Ah; seems to be a failure of seconds parsing: my $cron = Algorithm::Cron->new( base => 'utc', crontab => ' 20 23 1 1 *' ); is_deeply( [ $cron->min ], [ 20 ], '$cron->min for leading space' ); is_deeply( [ $cron->sec ], [ 0 ], '$cron->sec for leading space' ); fails # Failed test '$cron->sec for leading space' # at t/02cron.t line 93. # Structures begin differing at: # $got->[0] = Does not exist # $expected->[0] = '0' -- Paul Evans
Fixed by attached patch. -- Paul Evans
Subject: rt95454.patch
=== modified file 'lib/Algorithm/Cron.pm' --- lib/Algorithm/Cron.pm 2013-11-06 18:09:05 +0000 +++ lib/Algorithm/Cron.pm 2014-05-14 16:25:26 +0000 @@ -1,7 +1,7 @@ # You may distribute under the terms of either the GNU General Public License # or the Artistic License (the same terms as Perl itself) # -# (C) Paul Evans, 2012 -- leonerd@leonerd.org.uk +# (C) Paul Evans, 2012-2014 -- leonerd@leonerd.org.uk package Algorithm::Cron; @@ -251,6 +251,8 @@ if( exists $params{crontab} ) { my $crontab = delete $params{crontab}; + s/^\s+//, s/\s+$// for $crontab; + my @fields = split m/\s+/, $crontab; @fields >= 5 or croak "Expected at least 5 crontab fields"; @fields <= 6 or croak "Expected no more than 6 crontab fields"; === modified file 't/02cron.t' --- t/02cron.t 2013-04-06 19:14:15 +0000 +++ t/02cron.t 2014-05-14 16:25:26 +0000 @@ -82,4 +82,19 @@ dies_ok { Algorithm::Cron->new( crontab => 'one * * * *', base => 'utc' ) } 'Unrecognised number dies'; +# RT95454 +{ + my $cron = Algorithm::Cron->new( + base => 'utc', + crontab => ' 20 23 1 1 *' + ); + + is_deeply( [ $cron->min ], [ 20 ], '$cron->min for leading space' ); + is_deeply( [ $cron->sec ], [ 0 ], '$cron->sec for leading space' ); + + my $next = $cron->next_time( 0 ); + + is( $next, 84000, '->next_time for crontab with space' ); +} + done_testing;
On Wed May 14 12:40:19 2014, PEVANS wrote: Show quoted text
> Fixed by attached patch.
Thanks!
Released in 0.09 -- Paul Evans