jackc / tod

Time of day and shift types for Ruby
MIT License
435 stars 56 forks source link

strftime crashes when passing a frozen format string and 24 hour Tod #72

Open nathansamson opened 4 years ago

nathansamson commented 4 years ago

strftime crashes when passing a frozen format string and 24 hour Tod::TimeOfDay

This can happen when using # frozen_string_literal: true and a hardcoded format string.

nathan@muon app]$ irb
irb(main):001:0> require 'tod'
=> true
irb(main):002:0> Tod::TimeOfDay.new(24).strftime('%H:%M'.freeze)
Traceback (most recent call last):
        6: from /home/nathan/.rbenv/versions/2.6.6/bin/irb:23:in `<main>'
        5: from /home/nathan/.rbenv/versions/2.6.6/bin/irb:23:in `load'
        4: from /home/nathan/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/irb-1.2.4/exe/irb:11:in `<top (required)>'
        3: from (irb):2
        2: from /home/nathan/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/tod-2.2.0/lib/tod/time_of_day.rb:92:in `strftime'
        1: from /home/nathan/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/tod-2.2.0/lib/tod/time_of_day.rb:92:in `gsub!'
FrozenError (can't modify frozen String)
irb(main):003:0> 

Note this actualyl has been fixed in latest master (https://github.com/jackc/tod/commit/2e09f11349566f00f3dbbf64af8f6a97d7ffc202) but no release has been cut

jackc commented 4 years ago

Yeah, you'll have to use master for now.

I haven't want to make a release with a known bug on the latest release of Rails (https://github.com/jackc/tod/issues/65). A Rails 5.2.x point release broke something (I never found what). And when I just checked to see if Rails 6 was any better it turns out it has even more breakages (https://github.com/jackc/tod/issues/73).