From 22b16e1e37f253236c8508bb68280b2ce2c5ca37 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 17 Nov 2022 17:30:01 -0800 Subject: [PATCH] Ensure backslash is correctly handled in find-page-file (#43057) ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` Fixes: https://github.com/vercel/next.js/issues/43019#issuecomment-1319340037 --- packages/next/server/lib/find-page-file.ts | 2 +- test/unit/find-page-file.test.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/next/server/lib/find-page-file.ts b/packages/next/server/lib/find-page-file.ts index bba2122f002c11b..c59915de21f9529 100644 --- a/packages/next/server/lib/find-page-file.ts +++ b/packages/next/server/lib/find-page-file.ts @@ -67,6 +67,6 @@ export async function findPageFile( // The filename should start with 'page' and end with one of the allowed extensions export function isLayoutsLeafPage(filePath: string, pageExtensions: string[]) { return new RegExp( - `(^page|[\\/]page)\\.(?:${pageExtensions.join('|')})$` + `(^page|[\\\\/]page)\\.(?:${pageExtensions.join('|')})$` ).test(filePath) } diff --git a/test/unit/find-page-file.test.ts b/test/unit/find-page-file.test.ts index d49fb4347bd978d..e4972669e494773 100644 --- a/test/unit/find-page-file.test.ts +++ b/test/unit/find-page-file.test.ts @@ -53,6 +53,9 @@ describe('isLayoutsLeafPage', () => { expect(isLayoutsLeafPage('./page.jsx', pageExtensions)).toBe(true) expect(isLayoutsLeafPage('/page.ts', pageExtensions)).toBe(true) expect(isLayoutsLeafPage('/path/page.tsx', pageExtensions)).toBe(true) + expect(isLayoutsLeafPage('\\path\\page.tsx', pageExtensions)).toBe(true) + expect(isLayoutsLeafPage('.\\page.jsx', pageExtensions)).toBe(true) + expect(isLayoutsLeafPage('\\page.js', pageExtensions)).toBe(true) }) it('should determine other files under layout routes as non leaf node', () => {