Skip to content

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

Merged
svozza merged 4 commits into
mainfrom
fix/event-handler-router-prefix-joining
May 27, 2026
Merged

fix(event-handler): normalize trailing slashes in HTTP Router prefix joining#5255
svozza merged 4 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.

Comment thread packages/event-handler/src/http/utils.ts Fixed
@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
@svozza svozza requested a review from sdangol May 15, 2026 09:53
dreamorosi
dreamorosi previously approved these changes May 27, 2026
Comment thread packages/event-handler/src/http/utils.ts Outdated
svozza added 4 commits May 27, 2026 09:05
…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
Replace `replace(/\/+$/, '')` with a small `stripTrailingSlashes` helper
that walks the string from the end, keeping path normalization linear in
input length.
Promotes the inline rationale to a proper JSDoc block matching the
style used for nearby helpers, with @param/@returns annotations.
No behaviour change.
@svozza svozza force-pushed the fix/event-handler-router-prefix-joining branch from 3973bba to d8e0723 Compare May 27, 2026 08:06
@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 27, 2026
@sonarqubecloud
Copy link
Copy Markdown

@svozza svozza merged commit 7a500a1 into main May 27, 2026
40 checks passed
@svozza svozza deleted the fix/event-handler-router-prefix-joining branch May 27, 2026 08:09
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

3 participants