Skip to content

fix(router): allow RegExpRouter wildcard to match paths with line terminators - #5508

Open
akacolf wants to merge 2 commits into
honojs:mainfrom
akacolf:fix/regexp-router-wildcard-line-terminators
Open

akacolf wants to merge 2 commits into
honojs:mainfrom
akacolf:fix/regexp-router-wildcard-line-terminators

Conversation

@akacolf

@akacolf akacolf commented Oct 3, 2026 •

Copy link
Copy Markdown

The author should do the following, if applicable

  • Add tests
  • Run tests
  • pnpm run check:fix to format and lint the code
  • Add TSDoc/JSDoc to document the code

Description

In JavaScript regular expressions, . does not match line terminators (\n, \r, \u2028, \u2029) unless the s (dotAll) flag is enabled.

When request paths contain encoded line terminators (such as %0A, %0D), getPath() runs them through decodeURI, converting them into raw line terminators before routing. Consequently, wildcard routes (such as /* or *) and middleware registered in RegExpRouter failed to match and returned 404 Not Found, while other routers (TrieRouter, LinearRouter, PatternRouter) matched correctly.

This PR adds the s flag and documentation to:

  1. Trie.buildRegExp() in src/router/reg-exp-router/trie.ts
  2. buildWildcardRegExp() in src/router/reg-exp-router/router.ts

And adds tests covering paths with all four JavaScript line terminators across star, Trailing wildcard, and top-level Hono request handling.

Closes #5345

…minators

In JavaScript regex, '.' does not match line terminators (\n, \r, \u2028, \u2029) unless the 's' (dotAll) flag is set. When request paths contain encoded line terminators (such as %0A, %0D), decodeURI translates them into raw line terminators. As a result, wildcard routes (/* or *) in RegExpRouter failed to match and returned 404, while other routers matched correctly.

This adds the 's' (dotAll) flag to the compiled RegExp in Trie.buildRegExp() and buildWildcardRegExp() in RegExpRouter, ensuring wildcard routes and middleware match paths containing line terminators.

Fixes honojs#5345
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.

RegExpRouter: wildcard routes don't match paths containing an encoded line terminator (%0A, %0D)

1 participant