This repository was archived by the owner on Oct 14, 2024. It is now read-only.
File tree 2 files changed +12
-0
lines changed
AjaxControlToolkit/AjaxFileUpload
2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ public class AjaxFileUploadTests {
10
10
string _tempFolder ;
11
11
const string testBody = "------WebKitFormBoundaryCqenIHPHe1ZTCr0d\r \n Content-Disposition: form-data; name=\" act-file-data\" ; filename=\" zero.jpg\" \r \n Content-Type: image/jpeg\r \n \r \n \r \n ------WebKitFormBoundaryCqenIHPHe1ZTCr0d--\r \n " ;
12
12
const string testQuery = "filename=aaa.jpg&fileId=E63F2078-D5C7-66FA-5CAD-02C169149BD5" ;
13
+ const string testQueryFilenameInvalidChars = "filename=a:a*a.jpg&fileId=E63F2078-D5C7-66FA-5CAD-02C169149BD5" ;
13
14
const string testQueryNoExtension = "filename=aaa&fileId=E63F2078-D5C7-66FA-5CAD-02C169149BD5" ;
14
15
const string testContentType = "multipart/form-data; boundary=----WebKitFormBoundaryCqenIHPHe1ZTCr0d" ;
15
16
@@ -88,5 +89,13 @@ public void DoNotUseBufferlessInputStream() {
88
89
var context = new HttpContext ( request ) ;
89
90
Assert . DoesNotThrow ( ( ) => AjaxFileUploadHelper . Process ( context ) ) ;
90
91
}
92
+
93
+ [ Test ]
94
+ public void InvalidFilenameChars ( ) {
95
+ var request = new WorkerRequest ( testBody , testQueryFilenameInvalidChars , testContentType ) ;
96
+ var context = new HttpContext ( request ) ;
97
+ AjaxFileUploadHelper . Process ( context ) ;
98
+ Assert . True ( File . Exists ( Path . Combine ( _tempFolder , "E63F2078-D5C7-66FA-5CAD-02C169149BD5" , "a-a-a.jpg.tmp" ) ) ) ;
99
+ }
91
100
}
92
101
}
Original file line number Diff line number Diff line change @@ -201,6 +201,9 @@ static void CreateTempFilePathFolder(string tmpFilePath) {
201
201
202
202
private static string GetTempFilePath ( string fileId , string fileName ) {
203
203
var tempFolder = AjaxFileUpload . GetTempFolder ( fileId ) ;
204
+ foreach ( var invalidChar in Path . GetInvalidFileNameChars ( ) ) {
205
+ fileName = fileName . Replace ( invalidChar , '-' ) ;
206
+ }
204
207
return Path . Combine ( tempFolder , fileName ) + Constants . UploadTempFileExtension ;
205
208
}
206
209
}
You can’t perform that action at this time.
0 commit comments