@@ -345,6 +345,24 @@ def test_append_to_non_zip_file(self):
345345 with zipfile .ZipFile (f , "r" ) as zipfp :
346346 self .assertEqual (zipfp .namelist (), [TESTFN ])
347347
348+ def test_ignores_newline_at_end (self ):
349+ with zipfile .ZipFile (TESTFN2 , "w" , zipfile .ZIP_STORED ) as zipfp :
350+ zipfp .write (TESTFN , TESTFN )
351+ with open (TESTFN2 , 'a' ) as f :
352+ f .write ("\r \n \00 \00 \00 " )
353+ with zipfile .ZipFile (TESTFN2 , "r" ) as zipfp :
354+ self .assertIsInstance (zipfp , zipfile .ZipFile )
355+
356+ def test_ignores_stuff_appended_past_comments (self ):
357+ with zipfile .ZipFile (TESTFN2 , "w" , zipfile .ZIP_STORED ) as zipfp :
358+ zipfp .comment = b"this is a comment"
359+ zipfp .write (TESTFN , TESTFN )
360+ with open (TESTFN2 , 'a' ) as f :
361+ f .write ("abcdef\r \n " )
362+ with zipfile .ZipFile (TESTFN2 , "r" ) as zipfp :
363+ self .assertIsInstance (zipfp , zipfile .ZipFile )
364+ self .assertEqual (zipfp .comment , b"this is a comment" )
365+
348366 def test_write_default_name (self ):
349367 """Check that calling ZipFile.write without arcname specified
350368 produces the expected result."""
0 commit comments