From 072e50a7db973cec31a8badd662242f0ab2562e5 Mon Sep 17 00:00:00 2001 From: devjiwonchoi Date: Tue, 2 Jul 2024 00:17:19 +0900 Subject: [PATCH] chore: throw when three dot character is detected in segment --- packages/next/src/shared/lib/router/utils/sorted-routes.ts | 6 ++++++ test/unit/page-route-sorter.test.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/packages/next/src/shared/lib/router/utils/sorted-routes.ts b/packages/next/src/shared/lib/router/utils/sorted-routes.ts index 973126c8e0e58..67b67f88dcaa4 100644 --- a/packages/next/src/shared/lib/router/utils/sorted-routes.ts +++ b/packages/next/src/shared/lib/router/utils/sorted-routes.ts @@ -94,6 +94,12 @@ class UrlNode { isOptional = true } + if (segmentName.startsWith('…')) { + throw new Error( + `Detected a three-dot character ('…') at ('${segmentName}'). Did you mean ('...')?` + ) + } + if (segmentName.startsWith('...')) { // Strip `...`, leaving only `something` segmentName = segmentName.substring(3) diff --git a/test/unit/page-route-sorter.test.ts b/test/unit/page-route-sorter.test.ts index f197a4eb2e60f..1faa8ba0bd4b9 100644 --- a/test/unit/page-route-sorter.test.ts +++ b/test/unit/page-route-sorter.test.ts @@ -213,4 +213,10 @@ describe('getSortedRoutes', () => { ]) ).toThrow(/differ only by non-word/) }) + + it('catches param names start with three-dot character not actual three dots', () => { + expect(() => getSortedRoutes(['[…three-dots]'])).toThrow( + /Detected a three-dot character/ + ) + }) })