[PR #102] [MERGED] fix: normalize request pathname before middleware and route matching #311

Closed
opened 2026-05-06 12:39:07 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/102
Author: @southpolesteve
Created: 2/26/2026
Status: Merged
Merged: 2/26/2026
Merged by: @southpolesteve

Base: mainHead: fix/middleware-path-normalization


📝 Commits (2)

  • baff6f8 fix: normalize request pathname before middleware and route matching
  • 7fa1801 fix: restore tryServeStatic call for App Router static assets

📊 Changes

8 files changed (+531 additions, -223 deletions)

View changed files

📝 packages/vinext/src/index.ts (+19 -103)
📝 packages/vinext/src/server/app-dev-server.ts (+15 -90)
📝 packages/vinext/src/server/app-router-entry.ts (+18 -4)
packages/vinext/src/server/middleware-codegen.ts (+186 -0)
📝 packages/vinext/src/server/middleware.ts (+9 -8)
packages/vinext/src/server/normalize-path.ts (+54 -0)
📝 packages/vinext/src/server/prod-server.ts (+11 -10)
📝 tests/shims.test.ts (+219 -8)

📄 Description

Summary

  • Add normalizePath utility that collapses consecutive slashes (//foo///bar -> /foo/bar), resolves . and .. segments, and ensures a leading slash
  • Apply decodeURIComponent + normalizePath before middleware matching and route matching in all entry points (dev server, prod server, Cloudflare Worker entry, codegen entries)
  • Extract shared middleware codegen module (middleware-codegen.ts) as single source of truth for pattern matching logic, replacing hand-copied inline implementations in index.ts and app-dev-server.ts
  • Fix default middleware matcher to return true when no matcher is configured, matching Next.js behavior
  • Fix regex pattern handling in middleware matcher: patterns containing parentheses or backslashes are now passed to RegExp directly without dot-escaping, which previously corrupted patterns like /((?!api|_next).*)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/102 **Author:** [@southpolesteve](https://github.com/southpolesteve) **Created:** 2/26/2026 **Status:** ✅ Merged **Merged:** 2/26/2026 **Merged by:** [@southpolesteve](https://github.com/southpolesteve) **Base:** `main` ← **Head:** `fix/middleware-path-normalization` --- ### 📝 Commits (2) - [`baff6f8`](https://github.com/cloudflare/vinext/commit/baff6f8ebc0c7daabf857d328c32c3fba5e7b9aa) fix: normalize request pathname before middleware and route matching - [`7fa1801`](https://github.com/cloudflare/vinext/commit/7fa1801a3abdb31334c927aa2878a5f3cd8bebb1) fix: restore tryServeStatic call for App Router static assets ### 📊 Changes **8 files changed** (+531 additions, -223 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+19 -103) 📝 `packages/vinext/src/server/app-dev-server.ts` (+15 -90) 📝 `packages/vinext/src/server/app-router-entry.ts` (+18 -4) ➕ `packages/vinext/src/server/middleware-codegen.ts` (+186 -0) 📝 `packages/vinext/src/server/middleware.ts` (+9 -8) ➕ `packages/vinext/src/server/normalize-path.ts` (+54 -0) 📝 `packages/vinext/src/server/prod-server.ts` (+11 -10) 📝 `tests/shims.test.ts` (+219 -8) </details> ### 📄 Description ## Summary - Add `normalizePath` utility that collapses consecutive slashes (`//foo///bar` -> `/foo/bar`), resolves `.` and `..` segments, and ensures a leading slash - Apply `decodeURIComponent` + `normalizePath` before middleware matching and route matching in all entry points (dev server, prod server, Cloudflare Worker entry, codegen entries) - Extract shared middleware codegen module (`middleware-codegen.ts`) as single source of truth for pattern matching logic, replacing hand-copied inline implementations in `index.ts` and `app-dev-server.ts` - Fix default middleware matcher to return `true` when no matcher is configured, matching Next.js behavior - Fix regex pattern handling in middleware matcher: patterns containing parentheses or backslashes are now passed to RegExp directly without dot-escaping, which previously corrupted patterns like `/((?!api|_next).*)` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:39:08 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#311
No description provided.