jackc / jackc/tod

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

Open
#72 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
447
Forks
56
PR merge metrics
No merged PRs in 30d

Description

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 `'
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 `'
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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at lib/tod/time_of_day.rb:92 and reproduce the frozen-format failure with Tod::TimeOfDay.new(24). Compare the released behavior with the fix in commit 2e09f11349566f00f3dbbf64af8f6a97d7ffc202; the issue is done when the fix is available in a released version.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.