floraison / fugit

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

NoMethodError when parse'ing empty string #49

Closed gr8bit closed 3 years ago

gr8bit commented 3 years ago

Issue description

Parsing an empty string leads to NoMethodError instead of ArgumentError (when using do_parse) or nil (when using parse).

How to reproduce

require 'fugit'
Fugit::Cron.parse(' ')
 => nil 
Fugit::Cron.parse(nil)
 => nil 
Fugit::Cron.parse('')
Traceback (most recent call last):
        1: from (irb):20
NoMethodError (undefined method `subgather' for nil:NilClass)

Expected behaviour

Empty string should parse as invalid cron string, just like " " or nil.

Context

Linux 242fdceb1492 5.4.39-linuxkit #1 SMP Fri May 8 23:03:06 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
[:env_tz, nil]
(secs:1606866124.7550213,utc~:"2020-12-01 23:42:04.755021333694458",ltz~:"UTC")
(etz:nil,tnz:"UTC",tziv:"1.2.8",tzidv:nil,rv:"2.6.6",rp:"x86_64-linux",win:false,rorv:nil,astz:nil,eov:"1.2.4",eotnz:#<TZInfo::TimezoneProxy: Etc/UCT>,eotnfz:"+0000",eotlzn:"Etc/UCT",eotnfZ:"UTC",debian:"/UTC",centos:nil,osx:"/UTC")
"1.4.1"

Additional context

I'm using Fugit in Rails context.

jmettraux commented 3 years ago

Thanks for reporting this!

I think I fixed it. Please tell me if not.