Skip to content

Commit 22b16e1

Browse files
authored
Ensure backslash is correctly handled in find-page-file (vercel#43057)
## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` Fixes: vercel#43019 (comment)
1 parent 2f744a1 commit 22b16e1

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

packages/next/server/lib/find-page-file.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ export async function findPageFile(
6767
// The filename should start with 'page' and end with one of the allowed extensions
6868
export function isLayoutsLeafPage(filePath: string, pageExtensions: string[]) {
6969
return new RegExp(
70-
`(^page|[\\/]page)\\.(?:${pageExtensions.join('|')})$`
70+
`(^page|[\\\\/]page)\\.(?:${pageExtensions.join('|')})$`
7171
).test(filePath)
7272
}

test/unit/find-page-file.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ describe('isLayoutsLeafPage', () => {
5353
expect(isLayoutsLeafPage('./page.jsx', pageExtensions)).toBe(true)
5454
expect(isLayoutsLeafPage('/page.ts', pageExtensions)).toBe(true)
5555
expect(isLayoutsLeafPage('/path/page.tsx', pageExtensions)).toBe(true)
56+
expect(isLayoutsLeafPage('\\path\\page.tsx', pageExtensions)).toBe(true)
57+
expect(isLayoutsLeafPage('.\\page.jsx', pageExtensions)).toBe(true)
58+
expect(isLayoutsLeafPage('\\page.js', pageExtensions)).toBe(true)
5659
})
5760

5861
it('should determine other files under layout routes as non leaf node', () => {

0 commit comments

Comments
 (0)