Skip to content

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

Merged
eelcoj merged 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/publishable-impossible-filename-date
Oct 12, 2026
Merged

eelcoj merged 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/publishable-impossible-filename-date

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

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_date → published? → 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

@pcbeingused333

Copy link
Copy Markdown
Contributor 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.

`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.
@eelcoj
eelcoj force-pushed the fix/publishable-impossible-filename-date branch from a11002b to c72f946 Compare October 12, 2026 09:40
@eelcoj
eelcoj merged commit f9e600f into Rails-Designer:main Oct 12, 2026
3 checks passed
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.

2 participants