Skip to content

fix(event_handler): avoid double slash when router prefix ends with / - #8945

Open
Harshil-Jani wants to merge 1 commit into
aws-powertools:developfrom
Harshil-Jani:fix/event-handler-router-prefix-slash
Open

Harshil-Jani wants to merge 1 commit into
aws-powertools:developfrom
Harshil-Jani:fix/event-handler-router-prefix-slash

Conversation

@Harshil-Jani

Copy link
Copy Markdown

Issue number: closes #8944

Summary

Changes

include_router joined the prefix and the rule as f"{prefix}{rule}". With prefix="/p/" and a route /x that gave /p//x. Now the trailing / of the prefix is stripped when the rule starts with /. Rules without a leading slash (e.g. prefix="/users/" with <user_id>) are unchanged.

User experience

Before: include_router(router, prefix="/p/") with route /x returns 404 for GET /p/x.
After: it returns 200.

Verification

Added test_api_gateway_app_router_with_prefix_trailing_slash. It fails on develop (404 == 200) and passes with the fix. The event_handler functional and unit tests pass (1297 passed, 1 skipped). ruff format, ruff check and mypy are clean on the changed files. Checked with local events, not a real API Gateway.

I used Claude Code to help write this change; I reviewed and tested it myself.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@Harshil-Jani
Harshil-Jani requested a review from a team as a code owner December 2, 2026 17:30
@Harshil-Jani
Harshil-Jani requested a review from svozza December 2, 2026 17:30
@boring-cyborg

boring-cyborg Bot commented Dec 2, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 2, 2026
@sonarqubecloud

sonarqubecloud Bot commented Dec 2, 2026

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

event_handlers size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: include_router with a prefix ending in "/" registers "/p//x" and returns 404

1 participant