floraison / fugit

time tools (cron, parsing, durations, ...) for Ruby, rufus-scheduler, and flor
MIT License
384 stars 34 forks source link

Invalid “hours” in range cause cron #next_time loop breaker issue #30

Closed ticky closed 5 years ago

ticky commented 5 years ago

Issue description

Values outside 0-23 in an hour range cause an infinite loop error.

How to reproduce

require 'fugit'
c = Fugit.parse('* 0-24 * * *')
RuntimeError (too many loops for {:min=>0, :max=>23, :sta=>0, :edn=>24, :sla=>1} #range, breaking, please fill an issue at https://git.io/fjJC9)

Expected behaviour

The “24” being out of range should either result in a parsing error or being treated as 0.

Context

Please replace the content of this section with the output of the following commands:

Darwin Kinzie 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64
ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-darwin18]
(secs:1565722428.8614998,utc~:"2019-08-13 18:53:48.8614997863769531",ltz~:"PDT")
(etz:nil,tnz:"PDT",tziv:"1.2.5",tzidv:nil,rv:"2.6.2",rp:"x86_64-darwin18",win:false,rorv:nil,astz:nil,eov:"1.2.1",eotnz:#<TZInfo::TimezoneProxy: America/Dawson>,eotnfz:"-0700",eotlzn:"America/Dawson",eotnfZ:"PDT",debian:nil,centos:nil,osx:"zoneinfo/America/Vancouver")

Additional context

Encountered via in-the-wild user input!

jmettraux commented 5 years ago

https://crontab.guru/#*_0-24_*_*_* says 24 is not in the allowed values.

man 5 crontab says:

           field         allowed values
           -----         --------------
           minute        0-59
           hour          0-23
           day of month  1-31
           month         1-12 (or names, see below)
           day of week   0-7 (0 or 7 is Sun, or use names)

I should probably simply reject. But accepting 24, is lenient, à la Postel.

jmettraux commented 5 years ago

Already accepting 24 on its own, https://github.com/floraison/fugit/blob/12a2faabc1d5f66fc8b4c8c3795d6b32c154ac2d/spec/cron_spec.rb#L50 so have to be lenient.

jmettraux commented 5 years ago

Released as part of fugit 1.3.2.

https://rubygems.org/gems/fugit/versions/1.3.2

Please tell me if there is anything wrong.

Many thanks with this issue report.

ticky commented 5 years ago

Thanks for the quick fix! Looking good 😄