Skip to content

Commit

Permalink
Ensure backslash is correctly handled in find-page-file (#43057)
Browse files Browse the repository at this point in the history
## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

Fixes:
#43019 (comment)
  • Loading branch information
ijjk committed Nov 18, 2022
1 parent 2f744a1 commit 22b16e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
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

0 comments on commit 22b16e1

Please sign in to comment.