Skip to content

Commit

Permalink
Do not serve files when path ends with /
Browse files Browse the repository at this point in the history
  • Loading branch information
rmhaiderali committed Jan 20, 2024
1 parent b69cbb3 commit a420346
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,12 +715,16 @@ SendStream.prototype.sendFile = function sendFile (path) {

debug('stat "%s"', path)
fs.stat(path, function onstat (err, stat) {
if (err && err.code === 'ENOENT' && !extname(path) && path[path.length - 1] !== sep) {
var pathEndsWithSep = path[path.length - 1] === sep

if (err && err.code === 'ENOENT' && !extname(path) && !pathEndsWithSep) {
// not found, check extensions
return next(err)
}
if (err) return self.onStatError(err)
if (stat.isDirectory()) return self.redirect(path)
if(pathEndsWithSep) return self.error(404)

self.emit('file', path, stat)
self.send(path, stat)
})
Expand Down

0 comments on commit a420346

Please sign in to comment.