Skip to content

Commit

Permalink
c8
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday committed Mar 26, 2024
1 parent c0a9945 commit 514c326
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions index.js
Expand Up @@ -282,11 +282,10 @@ async function fastifyStatic (fastify, opts) {
if (opts.redirect === true) {
try {
reply.redirect(301, getRedirectUrl(request.raw.url))
} catch (error) {
} /* c8 ignore start */ catch (error) {
// the try-catch here is actually unreachable, but we keep it for safety and prevent DoS attack
/* c8 ignore next */
reply.send(error)
}
} /* c8 ignore stop */
} else {
// if is a directory path without a trailing slash, and has an index file, reply as if it has a trailing slash
if (!pathname.endsWith('/') && findIndexFile(pathname, options.root, options.index)) {
Expand Down Expand Up @@ -532,13 +531,12 @@ function getRedirectUrl (url) {
const parsed = new URL(url, 'http://localhost.com/')
const parsedPathname = parsed.pathname
return parsedPathname + (parsedPathname[parsedPathname.length - 1] !== '/' ? '/' : '') + (parsed.search || '')
} catch {
} /* c8 ignore start */ catch {
// the try-catch here is actually unreachable, but we keep it for safety and prevent DoS attack
/* c8 ignore next 3 */
const err = new Error(`Invalid redirect URL: ${url}`)
err.statusCode = 400
throw err
}
} /* c8 ignore stop */
}

module.exports = fp(fastifyStatic, {
Expand Down

0 comments on commit 514c326

Please sign in to comment.