@@ -244,11 +244,14 @@ public void WriteZipStreamWithNoCompression([Values(0, 1, 256)] int contentLengt
244244 using ( var dummyZip = Utils . GetDummyFile ( 0 ) )
245245 using ( var inputFile = Utils . GetDummyFile ( contentLength ) )
246246 {
247+ // Filename is manually cleaned here to prevent this test from failing while ZipEntry doesn't automatically clean it
248+ var inputFileName = ZipEntry . CleanName ( inputFile . Filename ) ;
249+
247250 using ( var zipFileStream = File . OpenWrite ( dummyZip . Filename ) )
248251 using ( var zipOutputStream = new ZipOutputStream ( zipFileStream ) )
249252 using ( var inputFileStream = File . OpenRead ( inputFile . Filename ) )
250253 {
251- zipOutputStream . PutNextEntry ( new ZipEntry ( inputFile . Filename )
254+ zipOutputStream . PutNextEntry ( new ZipEntry ( inputFileName )
252255 {
253256 CompressionMethod = CompressionMethod . Stored ,
254257 } ) ;
@@ -260,7 +263,6 @@ public void WriteZipStreamWithNoCompression([Values(0, 1, 256)] int contentLengt
260263 {
261264 var inputBytes = File . ReadAllBytes ( inputFile . Filename ) ;
262265
263- var inputFileName = ZipEntry . CleanName ( inputFile . Filename ) ;
264266 var entry = zf . GetEntry ( inputFileName ) ;
265267 Assert . IsNotNull ( entry , "No entry matching source file \" {0}\" found in archive, found \" {1}\" " , inputFileName , zf [ 0 ] . Name ) ;
266268
@@ -282,6 +284,35 @@ public void WriteZipStreamWithNoCompression([Values(0, 1, 256)] int contentLengt
282284 }
283285 }
284286
287+ [ Test ]
288+ [ Category ( "Zip" ) ]
289+ [ Category ( "KnownBugs" ) ]
290+ public void ZipEntryFileNameAutoClean ( )
291+ {
292+ using ( var dummyZip = Utils . GetDummyFile ( 0 ) )
293+ using ( var inputFile = Utils . GetDummyFile ( ) ) {
294+ using ( var zipFileStream = File . OpenWrite ( dummyZip . Filename ) )
295+ using ( var zipOutputStream = new ZipOutputStream ( zipFileStream ) )
296+ using ( var inputFileStream = File . OpenRead ( inputFile . Filename ) )
297+ {
298+ zipOutputStream . PutNextEntry ( new ZipEntry ( inputFile . Filename )
299+ {
300+ CompressionMethod = CompressionMethod . Stored ,
301+ } ) ;
302+
303+ inputFileStream . CopyTo ( zipOutputStream ) ;
304+ }
305+
306+ using ( var zf = new ZipFile ( dummyZip . Filename ) )
307+ {
308+ Assert . AreNotEqual ( ZipEntry . CleanName ( inputFile . Filename ) , zf [ 0 ] . Name ,
309+ "Entry file name \" {0}\" WAS automatically cleaned, this test should be removed" , inputFile . Filename ) ;
310+ }
311+
312+ Assert . Warn ( "Entry file name \" {0}\" was not automatically cleaned" , inputFile . Filename ) ;
313+ }
314+ }
315+
285316 /// <summary>
286317 /// Empty zips can be created and read?
287318 /// </summary>
0 commit comments