Skip to content

Commit 9774100

Browse files
authored
Do not serve files when path ends with / in windows (#224)
1 parent 672e5c3 commit 9774100

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,12 +605,14 @@ SendStream.prototype.sendFile = function sendFile (path) {
605605

606606
debug('stat "%s"', path)
607607
fs.stat(path, function onstat (err, stat) {
608-
if (err && err.code === 'ENOENT' && !extname(path) && path[path.length - 1] !== sep) {
608+
var pathEndsWithSep = path[path.length - 1] === sep
609+
if (err && err.code === 'ENOENT' && !extname(path) && !pathEndsWithSep) {
609610
// not found, check extensions
610611
return next(err)
611612
}
612613
if (err) return self.onStatError(err)
613614
if (stat.isDirectory()) return self.redirect(path)
615+
if (pathEndsWithSep) return self.error(404)
614616
self.emit('file', path, stat)
615617
self.send(path, stat)
616618
})

test/send.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,12 @@ describe('send(file, options)', function () {
11941194
.get('/')
11951195
.expect(200, /tobi/, done)
11961196
})
1197+
1198+
it('should 404 if file path contains trailing slash (windows)', function (done) {
1199+
request(createServer({ root: fixtures, index: false }))
1200+
.get('/tobi.html/')
1201+
.expect(404, done)
1202+
})
11971203
})
11981204

11991205
describe('root', function () {

0 commit comments

Comments
 (0)