fix(astro): prevent crash on unexpected file in pages (#2034)
* Skip files in `src/pages` when extension is not '.astro' or '.md' * Add test Fix #2033
This commit is contained in:
parent
e7feb425b8
commit
4436592d22
7 changed files with 28 additions and 1 deletions
5
.changeset/tame-hats-give.md
Normal file
5
.changeset/tame-hats-give.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix crash with unexpected file types in pages directory
|
|
@ -86,6 +86,7 @@ interface Item {
|
|||
export function createRouteManifest({ config, cwd }: { config: AstroConfig; cwd?: string }, logging: LogOptions): ManifestData {
|
||||
const components: string[] = [];
|
||||
const routes: RouteData[] = [];
|
||||
const validExtensions: Set<string> = new Set(['.astro', '.md']);
|
||||
|
||||
function walk(dir: string, parentSegments: Part[][], parentParams: string[]) {
|
||||
let items: Item[] = [];
|
||||
|
@ -104,7 +105,7 @@ export function createRouteManifest({ config, cwd }: { config: AstroConfig; cwd?
|
|||
return;
|
||||
}
|
||||
// filter out "foo.astro_tmp" files, etc
|
||||
if (!isDir && !/^(\.[a-z0-9]+)+$/i.test(ext)) {
|
||||
if (!isDir && !validExtensions.has(ext)) {
|
||||
return;
|
||||
}
|
||||
const segment = isDir ? basename : name;
|
||||
|
|
0
packages/astro/test/fixtures/route-manifest/invalid-extension/about.astro
vendored
Normal file
0
packages/astro/test/fixtures/route-manifest/invalid-extension/about.astro
vendored
Normal file
0
packages/astro/test/fixtures/route-manifest/invalid-extension/image.svg
vendored
Normal file
0
packages/astro/test/fixtures/route-manifest/invalid-extension/image.svg
vendored
Normal file
0
packages/astro/test/fixtures/route-manifest/invalid-extension/index.astro
vendored
Normal file
0
packages/astro/test/fixtures/route-manifest/invalid-extension/index.astro
vendored
Normal file
0
packages/astro/test/fixtures/route-manifest/invalid-extension/styles.css
vendored
Normal file
0
packages/astro/test/fixtures/route-manifest/invalid-extension/styles.css
vendored
Normal file
|
@ -184,6 +184,27 @@ describe('route manifest', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
it('ignores invalid route extensions', () => {
|
||||
const { routes } = create('invalid-extension', 'always');
|
||||
expect(cleanRoutes(routes)).to.deep.equal([
|
||||
{
|
||||
type: 'page',
|
||||
pattern: /^\/$/,
|
||||
params: [],
|
||||
component: 'invalid-extension/index.astro',
|
||||
pathname: '/',
|
||||
},
|
||||
|
||||
{
|
||||
type: 'page',
|
||||
pattern: /^\/about\/$/,
|
||||
params: [],
|
||||
component: 'invalid-extension/about.astro',
|
||||
pathname: '/about',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('allows multiple slugs', () => {
|
||||
const { routes } = create('multiple-slugs', 'always');
|
||||
|
||||
|
|
Loading…
Reference in a new issue