Skip to content

fix(event-handler): normalize trailing slashes in HTTP Router prefix joining#5255

Open
svozza wants to merge 3 commits into
mainfrom
fix/event-handler-router-prefix-joining
Open

fix(event-handler): normalize trailing slashes in HTTP Router prefix joining#5255
svozza wants to merge 3 commits into
mainfrom
fix/event-handler-router-prefix-joining

Conversation

@svozza
Copy link
Copy Markdown
Contributor

@svozza svozza commented May 14, 2026

Summary

Router registered route ids did not handle trailing slashes consistently: a root route under a prefix (e.g. app.get('/', …) with prefix: '/api') was unreachable from /api/, and a prefix that accidentally ended with / produced double slashes in the route id (e.g. '/api//users'), breaking matches.

Changes

  • resolvePrefixedPath now strips trailing slashes from the prefix before joining, so '/api' and '/api/' produce the same result and no // appears in the route id.
  • Router.resolve normalizes incoming request paths the same way (preserving / itself), so a route registered as / under prefix /api matches both /api and /api/.
  • Added unit cases for resolvePrefixedPath covering prefix-with-trailing-slash inputs, and integration tests in basic-routing.test.ts for both bug scenarios from the issue.
  • Updated the resolvePrefixedPath JSDoc to document the normalization preconditions.

Issue number: closes #5252


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.

…HTTP Router

resolvePrefixedPath now strips trailing slashes off the prefix before joining,
preventing double slashes when prefix already ends with `/`. Router.resolve
normalizes incoming request paths the same way (preserving `/` itself) so a
route registered with path `/` under prefix `/api` matches both `/api` and
`/api/`.

Closes #5252
Comment thread packages/event-handler/src/http/utils.ts Fixed
Replace `replace(/\/+$/, '')` with a small `stripTrailingSlashes` helper
that walks the string from the end, keeping path normalization linear in
input length.
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/M PR between 30-99 LOC and removed size/M PR between 30-99 LOC labels May 14, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/M PR between 30-99 LOC and removed size/M PR between 30-99 LOC labels May 15, 2026
@sonarqubecloud
Copy link
Copy Markdown

@svozza svozza requested a review from sdangol May 15, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M PR between 30-99 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: event-handler HTTP Router prefix joining drops trailing slash and produces double slashes

2 participants