Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure backslash is correctly handled in find-page-file #43057

Merged
merged 1 commit into from Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/server/lib/find-page-file.ts
Expand Up @@ -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)
}
3 changes: 3 additions & 0 deletions test/unit/find-page-file.test.ts
Expand Up @@ -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', () => {
Expand Down