Fix 500 on open-ended date range in donations#index#5634
Open
dylangriffinshub wants to merge 1 commit into
Open
Fix 500 on open-ended date range in donations#index#5634dylangriffinshub wants to merge 1 commit into
dylangriffinshub wants to merge 1 commit into
Conversation
DateRangeHelper#selected_interval only rescued Date.strptime raising, but an open-ended range from the picker (e.g. "August 25, 2025 - ", with no end date filled in) parses without error into a single-element array. Destructuring start_date, end_date = selected_interval then leaves end_date as nil, which blows up later in selected_range_described's end_date.to_fs(:short) call with a NoMethodError. Fixes rubyforgood#5608 Now selected_interval falls back to the default date range (with the existing "Invalid Date range provided" flash notice) whenever fewer than 2 valid dates are parsed, not just when strptime raises.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5608 — Bugsnag reported a
NoMethodError(undefined method 'to_fs' for nil) ondonations#indexwhen a bank enters an open-ended date range in the date picker.DateRangeHelper#selected_intervalonly rescuedDate.strptimeraising an exception. An open-ended range like"August 25, 2025 - "(only the start date filled in) parses without error:.split(" - ")produces a single-element array, so.maponly yields one date, and the destructuringstart_date, end_date = selected_intervalsilently leavesend_dateasnil. Thatnilthen hitsend_date.to_fs(:short)inselected_range_described, causing the 500.Fix
selected_intervalnow falls back to the default date range (same "Invalid Date range provided. Reset to default date range" flash notice already used for unparseable ranges) whenever fewer than 2 valid dates are parsed, not only whenstrptimeraises.Test plan
bundle exec rspec spec/helpers/date_range_helper_spec.rbselected_interval, plus a spec assertingselected_range_describedno longer raises in that case