Unverified Commit 22b16e1e authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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
parent 2f744a1a
...@@ -67,6 +67,6 @@ export async function findPageFile( ...@@ -67,6 +67,6 @@ export async function findPageFile(
// The filename should start with 'page' and end with one of the allowed extensions // The filename should start with 'page' and end with one of the allowed extensions
export function isLayoutsLeafPage(filePath: string, pageExtensions: string[]) { export function isLayoutsLeafPage(filePath: string, pageExtensions: string[]) {
return new RegExp( return new RegExp(
`(^page|[\\/]page)\\.(?:${pageExtensions.join('|')})$` `(^page|[\\\\/]page)\\.(?:${pageExtensions.join('|')})$`
).test(filePath) ).test(filePath)
} }
...@@ -53,6 +53,9 @@ describe('isLayoutsLeafPage', () => { ...@@ -53,6 +53,9 @@ describe('isLayoutsLeafPage', () => {
expect(isLayoutsLeafPage('./page.jsx', pageExtensions)).toBe(true) expect(isLayoutsLeafPage('./page.jsx', pageExtensions)).toBe(true)
expect(isLayoutsLeafPage('/page.ts', 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('\\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', () => { it('should determine other files under layout routes as non leaf node', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment