From 86576ef4fc1a906566ecfbbd438232fc6a030bf9 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 20 Jul 2020 12:37:04 -0400 Subject: [PATCH 1/2] Simplify trailing slash regex --- packages/next/lib/load-custom-routes.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/lib/load-custom-routes.ts b/packages/next/lib/load-custom-routes.ts index 62755463bb50f..0879802ca94d9 100644 --- a/packages/next/lib/load-custom-routes.ts +++ b/packages/next/lib/load-custom-routes.ts @@ -365,8 +365,8 @@ export default async function loadCustomRoutes( permanent: true, }, { - source: '/:path*/:notfile([^/.]+)', - destination: '/:path*/:notfile/', + source: '/:notfile((?:[^/]+/)*[^/\\.]+)', + destination: '/:notfile/', permanent: true, } ) From dd49d917cdef67e832e027d459b65dabcc6eea97 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Mon, 20 Jul 2020 12:52:53 -0400 Subject: [PATCH 2/2] Update tests --- packages/next/lib/load-custom-routes.ts | 4 ++-- test/integration/trailing-slashes/test/index.test.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/next/lib/load-custom-routes.ts b/packages/next/lib/load-custom-routes.ts index 0879802ca94d9..b044c6592c426 100644 --- a/packages/next/lib/load-custom-routes.ts +++ b/packages/next/lib/load-custom-routes.ts @@ -360,8 +360,8 @@ export default async function loadCustomRoutes( if (config.trailingSlash) { redirects.unshift( { - source: '/:path*/:file.:ext/', - destination: '/:path*/:file.:ext', + source: '/:file((?:[^/]+/)*[^/]+\\.\\w+)/', + destination: '/:file', permanent: true, }, { diff --git a/test/integration/trailing-slashes/test/index.test.js b/test/integration/trailing-slashes/test/index.test.js index 3068d0d2b6d55..24c58e6170fad 100644 --- a/test/integration/trailing-slashes/test/index.test.js +++ b/test/integration/trailing-slashes/test/index.test.js @@ -258,13 +258,13 @@ describe('Trailing slashes', () => { expect.objectContaining({ redirects: expect.arrayContaining([ expect.objectContaining({ - source: '/:path*/:file.:ext/', - destination: '/:path*/:file.:ext', + source: '/:file((?:[^/]+/)*[^/]+\\.\\w+)/', + destination: '/:file', statusCode: 308, }), expect.objectContaining({ - source: '/:path*/:notfile([^/.]+)', - destination: '/:path*/:notfile/', + source: '/:notfile((?:[^/]+/)*[^/\\.]+)', + destination: '/:notfile/', statusCode: 308, }), ]),