Skip to content

Commit

Permalink
fix: handling of empty redirect #99
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Jun 28, 2024
1 parent 69b2647 commit 3812723
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions reserve/src/handlers/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,12 @@ module.exports = {
}
},
redirect: ({ request, mapping, redirect, response }) => {
let filePath = /([^?#]+)/.exec(redirect)[1] // filter URL parameters & hash
let filePath = /([^?#]*)/.exec(redirect)[1] // filter URL parameters & hash
filePath = join(mapping.cwd, filePath)
if (!filePath.startsWith(mapping.cwd)) {
return Promise.resolve()
}
const directoryAccess = !!filePath.match(/(\\|\/)$/) // Test known path separators
if (directoryAccess) {
filePath = filePath.substring(0, filePath.length - 1)
}
const fileAccess = !filePath.match(/(\\|\/)$/) // Test known path separators
const context = {
cachingStrategy: mapping[$cachingStrategy],
fs: mapping[$customFileSystem],
Expand All @@ -200,7 +197,7 @@ module.exports = {
.then(async stat => {
await checkStrictPath(context.fs, mapping.cwd, filePath)
const isDirectory = stat.isDirectory()
if (isDirectory ^ directoryAccess) {
if (!isDirectory && !fileAccess) {
return
}
if (isDirectory) {
Expand Down

0 comments on commit 3812723

Please sign in to comment.