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' ) ;
4
4
5
5
module . exports = function ( options ) {
6
6
options = options || { } ;
@@ -21,9 +21,11 @@ module.exports = function(options) {
21
21
22
22
req . busboy . on ( 'file' , function ( fieldname , file , filename , encoding , mimetype ) {
23
23
var buf = new Buffer ( 0 ) ;
24
+ var safeFileNameRegex = / [ ^ \w - ] / g;
24
25
25
26
file . on ( 'data' , function ( data ) {
26
27
buf = Buffer . concat ( [ buf , data ] ) ;
28
+
27
29
if ( options . debug ) {
28
30
return console . log ( 'Uploading %s -> %s' , fieldname , filename ) ;
29
31
}
@@ -33,14 +35,21 @@ module.exports = function(options) {
33
35
if ( ! req . files )
34
36
req . files = { } ;
35
37
36
-
37
38
// see: https://github.com/richardgirges/express-fileupload/issues/14
38
39
// firefox uploads empty file in case of cache miss when f5ing page.
39
40
// resulting in unexpected behavior. if there is no file data, the file is invalid.
40
-
41
41
if ( ! buf . length )
42
42
return ;
43
43
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
+
44
53
return req . files [ fieldname ] = {
45
54
name : filename ,
46
55
data : buf ,
@@ -58,8 +67,6 @@ module.exports = function(options) {
58
67
} ) ;
59
68
}
60
69
} ;
61
-
62
-
63
70
} ) ;
64
71
} ) ;
65
72
0 commit comments