[PR #1054] [MERGED] fix(routing): accept any non-] chars in dynamic segment names (Next.js parity) #1051

Closed
opened 2026-05-06 13:11:45 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/1054
Author: @NathanDrake2406
Created: 5/4/2026
Status: Merged
Merged: 5/5/2026
Merged by: @james-elicx

Base: mainHead: fix/routing-dynamic-segments-and-precedence


📝 Commits (1)

  • 281dafd fix(routing): accept any non-] chars in dynamic segment names (Next.js parity)

📊 Changes

9 files changed (+178 additions, -19 deletions)

View changed files

📝 packages/vinext/src/entries/pages-server-entry.ts (+6 -3)
📝 packages/vinext/src/routing/app-route-graph.ts (+11 -3)
📝 packages/vinext/src/routing/pages-router.ts (+12 -6)
📝 packages/vinext/src/routing/route-validation.ts (+6 -3)
📝 packages/vinext/src/routing/utils.ts (+4 -1)
📝 packages/vinext/src/shims/router.ts (+4 -3)
📝 tests/app-route-graph.test.ts (+50 -0)
📝 tests/route-sorting.test.ts (+16 -0)
📝 tests/routing.test.ts (+69 -0)

📄 Description

Summary

Aligns vinext's dynamic segment name parsing with Next.js PARAMETER_PATTERN, which accepts any non-\] characters inside brackets. vinext was restricting param names to [\w-]+, silently treating valid Next.js segments like [repo:name], [variant.id], and [user@domain] as literal URL segments.

Changes

Regex fixes (4 files)

File Before After
routing/app-route-graph.ts /^\[\.\.\.([\w-]+)\]$/ /^\[\.\.\.([^\]]+)\]$/
routing/pages-router.ts same same
routing/route-validation.ts /:([\w-]+)\+/g /:([^/]+)\+/g
shims/router.ts \[{1,2}(?:\.\.\.)?([\w-]+)\]{1,2} \[{1,2}(?:\.\.\.)?([^\]]+)\]{1,2}

Next.js reference

Test coverage

Added a test in tests/app-route-graph.test.ts that verifies routes with dotted, colon, and at-sign param names are materialized correctly.


🔄 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/1054 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 5/4/2026 **Status:** ✅ Merged **Merged:** 5/5/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/routing-dynamic-segments-and-precedence` --- ### 📝 Commits (1) - [`281dafd`](https://github.com/cloudflare/vinext/commit/281dafdabec20a2616ba359b9a10bb03d21cd8a3) fix(routing): accept any non-] chars in dynamic segment names (Next.js parity) ### 📊 Changes **9 files changed** (+178 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/pages-server-entry.ts` (+6 -3) 📝 `packages/vinext/src/routing/app-route-graph.ts` (+11 -3) 📝 `packages/vinext/src/routing/pages-router.ts` (+12 -6) 📝 `packages/vinext/src/routing/route-validation.ts` (+6 -3) 📝 `packages/vinext/src/routing/utils.ts` (+4 -1) 📝 `packages/vinext/src/shims/router.ts` (+4 -3) 📝 `tests/app-route-graph.test.ts` (+50 -0) 📝 `tests/route-sorting.test.ts` (+16 -0) 📝 `tests/routing.test.ts` (+69 -0) </details> ### 📄 Description ## Summary Aligns vinext's dynamic segment name parsing with Next.js `PARAMETER_PATTERN`, which accepts **any non-`\]` characters** inside brackets. vinext was restricting param names to `[\w-]+`, silently treating valid Next.js segments like `[repo:name]`, `[variant.id]`, and `[user@domain]` as literal URL segments. ## Changes ### Regex fixes (4 files) | File | Before | After | |------|--------|-------| | `routing/app-route-graph.ts` | `/^\[\.\.\.([\w-]+)\]$/` | `/^\[\.\.\.([^\]]+)\]$/` | | `routing/pages-router.ts` | same | same | | `routing/route-validation.ts` | `/:([\w-]+)\+/g` | `/:([^/]+)\+/g` | | `shims/router.ts` | `\[{1,2}(?:\.\.\.)?([\w-]+)\]{1,2}` | `\[{1,2}(?:\.\.\.)?([^\]]+)\]{1,2}` | ## Next.js reference - **`PARAMETER_PATTERN`**: [packages/next/src/shared/lib/router/utils/get-dynamic-param.ts#L175](https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/router/utils/get-dynamic-param.ts#L175) ```ts export const PARAMETER_PATTERN = /^([^[]*)\[((?:\[[^\]]*\])|[^\]]+)\](.*)$/ ``` The `[^\]]+` group matches any character except `\]`, which is why `[repo:name]` is valid in Next.js. ## Test coverage Added a test in `tests/app-route-graph.test.ts` that verifies routes with dotted, colon, and at-sign param names are materialized correctly. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:11:45 +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#1051
No description provided.