Skip to content

Fix PagesController slug derivation for root and custom paths - #78

Merged
kanejamison merged 2 commits into
mainfrom
claude/github-issue-57-qra2nq
Jul 23, 2026
Merged

Fix PagesController slug derivation for root and custom paths#78
kanejamison merged 2 commits into
mainfrom
claude/github-issue-57-qra2nq

Conversation

@kanejamison

@kanejamison kanejamison commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #57

Fixes a regression where PagesController was unable to render pages configured with root paths (bunko_page :home, path: "/") or custom paths (bunko_page :about, path: "about-us"). The controller was incorrectly deriving the page slug by parsing request.path instead of reading it from the route's defaults: {page: ...} parameter.

Key Changes

  • PagesController slug derivation: Changed from parsing request.path to reading params[:page] (which contains the route default). Route defaults take precedence over query string parameters in Rails, preventing query string manipulation attacks while supporting all path configurations.

  • Format validation: Added a format guard (/\A[a-z0-9-]+\z/) to validate the slug before querying the database, ensuring the controller fails safely if wired up without a :page default.

  • Updated templates: Applied the same fix to the PagesController template (lib/tasks/templates/controllers/pages_controller.rb.tt) so newly generated controllers use the correct approach.

  • Regression tests: Added comprehensive test coverage for the fixed behavior:

    • Root path pages (bunko_page :home, path: "/")
    • Custom path pages (bunko_page :about, path: "about-us")
    • Query parameter override prevention (route defaults win over query strings)
    • Helper method draw_dummy_routes_with for dynamically testing route configurations
  • Documentation: Updated CHANGELOG.md with the fix details and GitHub issue reference (PagesController slug derivation breaks root path and custom paths #57). Also documented the "Closes #xx" convention for future tickets in CLAUDE.md.

Implementation Details

The fix leverages Rails' route parameter precedence: when a route defines defaults: {page: "about"}, that value is merged into params and takes precedence over any query string parameter with the same name. This provides both security (prevents path traversal via query strings) and correctness (works with any path configuration).

https://claude.ai/code/session_019SzbpeC8uQM8DmEPpi86vT

claude added 2 commits July 23, 2026 05:36
Deriving the page slug from request.path broke two cases:
- bunko_page :home, path: "/" resolved to a nil slug and 404ed
- bunko_page :about, path: "about-us" looked up "about-us" instead of
  the post's actual slug "about"

Read params[:page] instead, which bunko_page already provides via
defaults: {page: ...}. Route defaults are path parameters and take
precedence over query string params in Rails, so the query string
still cannot override the slug. A format guard 404s if the action is
ever wired up without a :page default.

Updates the template and the committed namespaced dummy controller in
sync, and adds regression tests for root-path pages, custom-path
pages, and query-param override attempts.

Fixes #57

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019SzbpeC8uQM8DmEPpi86vT
Always mark PRs and commits with "Closes #xx" / "Fixes #xx" when
working on a ticket so the issue auto-closes on merge.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019SzbpeC8uQM8DmEPpi86vT
@kanejamison
kanejamison merged commit bc339a3 into main Jul 23, 2026
4 checks passed
@kanejamison
kanejamison deleted the claude/github-issue-57-qra2nq branch July 23, 2026 05:51
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.

PagesController slug derivation breaks root path and custom paths

2 participants