Skip to content

Commit 4cee35d

Browse files
authored
fix: gracefully handle mssing middleware (#821)
Release-As: 4.0.0-beta.9
1 parent 89890ba commit 4cee35d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/helpers/files.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const stripLocale = (rawPath, locales = []) => {
2222
}
2323

2424
const matchMiddleware = (middleware, filePath) =>
25-
middleware.includes('') ||
25+
middleware?.includes('') ||
2626
middleware?.find(
2727
(middlewarePath) =>
2828
filePath === middlewarePath || filePath === `${middlewarePath}.html` || filePath.startsWith(`${middlewarePath}/`),

test/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,22 @@ describe('utility functions', () => {
410410
}
411411
})
412412

413+
test('middleware tester matches root middleware', () => {
414+
const paths = [
415+
'middl',
416+
'',
417+
'somethingelse',
418+
'another.html',
419+
'another/middle.html',
420+
'sub/anotherdirectory.html',
421+
'sub/directoryelse',
422+
'sub/directoryelse.html',
423+
]
424+
for (const path of paths) {
425+
expect(matchMiddleware(undefined, path)).toBeFalsy()
426+
}
427+
})
428+
413429
test('stripLocale correctly strips matching locales', () => {
414430
const locales = ['en', 'fr', 'en-GB']
415431
const paths = [

0 commit comments

Comments
 (0)