Skip to content

Don't crash on an impossible date in a resource filename - #216

Open
pcbeingused333 wants to merge 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/publishable-impossible-filename-date
Open

pcbeingused333 wants to merge 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/publishable-impossible-filename-date

Conversation

@pcbeingused333

Copy link
Copy Markdown

The bug

Publishable#date_from_filename matches /^\d{4}-\d{2}-\d{2}-/ and hands the captured groups to Date.new:

Date.new(match[:year].to_i, match[:month].to_i, match[:day].to_i)

The regex is structural, so 2024-99-99-post.md matches and Date.new(2024, 99, 99) raises Date::Error: invalid date. It propagates through publication_datepublished?Collection#all, so one typo'd filename breaks the whole collection load.

The fix

Rescue Date::Error and treat the prefix as not-a-date — the same outcome as a filename with no date prefix.

Tests

resource_publishable_test.rb — a 2024-99-99-…md file: publication_date is nil and published? doesn't raise. Fails on main (Date::Error). bundle exec rake is green (402 runs, 0 failures; standardrb clean).

🤖 Generated with Claude Code

`date_from_filename` matches `\d{4}-\d{2}-\d{2}-` and passes the parts
straight to `Date.new`, so a file named `2024-99-99-post.md` raises
`Date::Error: invalid date`. That propagates through `publication_date`
and `published?`, so a single typo'd filename takes down the whole
collection load.

Rescue `Date::Error` and treat the prefix as not-a-date, the same as a
filename with no date prefix at all.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GtYgwYNfJ3wHrw9xrooVoB
@pcbeingused333

Copy link
Copy Markdown
Author

CI is on action_required (fork gate). Verified with bundle exec rake (Docker, Ruby 3.4): 402 runs, 0 failures, standardrb clean. The new test fails on main with Date::Error: invalid date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant