1- var busboy = require ( 'connect-busboy' ) ,
2- fs = require ( 'fs-extra' ) ,
3- streamifier = require ( 'streamifier' ) ;
1+ var busboy = require ( 'connect-busboy' ) ;
2+ var fs = require ( 'fs-extra' ) ;
3+ var streamifier = require ( 'streamifier' ) ;
44
55module . exports = function ( options ) {
66 options = options || { } ;
@@ -21,9 +21,11 @@ module.exports = function(options) {
2121
2222 req . busboy . on ( 'file' , function ( fieldname , file , filename , encoding , mimetype ) {
2323 var buf = new Buffer ( 0 ) ;
24+ var safeFileNameRegex = / [ ^ \w - ] / g;
2425
2526 file . on ( 'data' , function ( data ) {
2627 buf = Buffer . concat ( [ buf , data ] ) ;
28+
2729 if ( options . debug ) {
2830 return console . log ( 'Uploading %s -> %s' , fieldname , filename ) ;
2931 }
@@ -33,14 +35,21 @@ module.exports = function(options) {
3335 if ( ! req . files )
3436 req . files = { } ;
3537
36-
3738 // see: https://github.com/richardgirges/express-fileupload/issues/14
3839 // firefox uploads empty file in case of cache miss when f5ing page.
3940 // resulting in unexpected behavior. if there is no file data, the file is invalid.
40-
4141 if ( ! buf . length )
4242 return ;
4343
44+ if ( options . safeFileNames ) {
45+ if ( typeof options . safeFileNames === 'object' )
46+ safeFileNameRegex = options . safeFileNames ;
47+
48+ filename = filename . replace ( safeFileNameRegex , '' ) ;
49+
50+ console . log ( 'filename yo' , filename ) ;
51+ }
52+
4453 return req . files [ fieldname ] = {
4554 name : filename ,
4655 data : buf ,
@@ -58,8 +67,6 @@ module.exports = function(options) {
5867 } ) ;
5968 }
6069 } ;
61-
62-
6370 } ) ;
6471 } ) ;
6572
0 commit comments