Skip to content

Commit 6bcdfef

Browse files
thevoidfdougwilson
authored andcommitted
Improve error message for non-strings to res.sendFile
closes #3582
1 parent 44e539e commit 6bcdfef

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased
2+
==========
3+
4+
* Improve error message for non-strings to `res.sendFile`
5+
16
4.16.4 / 2018-10-10
27
===================
38

lib/response.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ res.sendFile = function sendFile(path, options, callback) {
411411
throw new TypeError('path argument is required to res.sendFile');
412412
}
413413

414+
if (typeof path !== 'string') {
415+
throw new TypeError('path must be a string to res.sendFile')
416+
}
417+
414418
// support function as second arg
415419
if (typeof options === 'function') {
416420
done = options;

test/res.sendFile.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ describe('res', function(){
2020
.expect(500, /path.*required/, done);
2121
});
2222

23+
it('should error for non-string path', function (done) {
24+
var app = createApp(42)
25+
26+
request(app)
27+
.get('/')
28+
.expect(500, /TypeError: path must be a string to res.sendFile/, done)
29+
})
30+
2331
it('should transfer a file', function (done) {
2432
var app = createApp(path.resolve(fixtures, 'name.txt'));
2533

0 commit comments

Comments
 (0)