@@ -232,12 +232,12 @@ async function fastifyStatic (fastify, opts) {
232232 /**
233233 * @param {import("fastify").FastifyReply } reply
234234 * @param {string } pathname
235+ * @param {string } dotfiles
235236 * @return {Promise<boolean> }
236237 */
237- async function sendDirectoryList ( reply , pathname ) {
238- // never list a directory whose path contains a dotfile segment when
239- // dotfiles are denied or ignored: the 403/404 from send must stand
240- if ( opts . dotfiles !== 'allow' && containsDotFile ( pathname ) ) {
238+ async function sendDirectoryList ( reply , pathname , dotfiles ) {
239+ // Keep send's dotfile denial intact; its 403 is not a missing index.
240+ if ( dotfiles !== 'allow' && containsDotFile ( pathname ) ) {
241241 return false
242242 }
243243
@@ -255,7 +255,7 @@ async function fastifyStatic (fastify, opts) {
255255 options : opts . list ,
256256 route : pathname ,
257257 prefix,
258- dotfiles : opts . dotfiles
258+ dotfiles
259259 } ) . catch ( ( err ) => reply . send ( err ) )
260260
261261 return true
@@ -426,7 +426,7 @@ async function fastifyStatic (fastify, opts) {
426426 options : opts . list ,
427427 route : pathname ,
428428 prefix,
429- dotfiles : opts . dotfiles
429+ dotfiles : options . dotfiles
430430 } ) . catch ( ( err ) => reply . send ( err ) )
431431 }
432432
@@ -462,7 +462,7 @@ async function fastifyStatic (fastify, opts) {
462462 ( ! options . index || ! options . index . length ) &&
463463 pathnameForSend [ pathnameForSend . length - 1 ] === '/'
464464 ) {
465- if ( opts . list && await sendDirectoryList ( reply , pathname ) ) {
465+ if ( opts . list && await sendDirectoryList ( reply , pathname , options . dotfiles ) ) {
466466 return
467467 }
468468 }
@@ -488,7 +488,7 @@ async function fastifyStatic (fastify, opts) {
488488 }
489489
490490 // if file exists, send real file, otherwise send dir list if name match
491- if ( opts . list && dirList . handle ( pathname , opts . list ) && await sendDirectoryList ( reply , pathname ) ) {
491+ if ( opts . list && dirList . handle ( pathname , opts . list ) && await sendDirectoryList ( reply , pathname , options . dotfiles ) ) {
492492 return
493493 }
494494
@@ -1067,10 +1067,6 @@ function decodePathname (pathname) {
10671067 return decodeURI ( pathname . replace ( encodedHashOrQuestionMarkRegex , decodeURIComponent ) )
10681068}
10691069
1070- /**
1071- * @param {string } url
1072- * @return {string }
1073- */
10741070/**
10751071 * Whether any segment of a URL pathname is a dotfile (`.foo`), mirroring
10761072 * `@fastify/send`'s check (`.` alone is not a dotfile).
@@ -1081,6 +1077,10 @@ function containsDotFile (pathname) {
10811077 return pathname . split ( '/' ) . some ( ( s ) => s . length > 1 && s [ 0 ] === '.' )
10821078}
10831079
1080+ /**
1081+ * @param {string } url
1082+ * @return {string }
1083+ */
10841084function getRedirectUrl ( url ) {
10851085 let i = 0
10861086 // we detect how many slash before a valid path
0 commit comments