@@ -351,6 +351,24 @@ def test_append_to_non_zip_file(self):
351351 with zipfile .ZipFile (f , "r" ) as zipfp :
352352 self .assertEqual (zipfp .namelist (), [TESTFN ])
353353
354+ def test_ignores_newline_at_end (self ):
355+ with zipfile .ZipFile (TESTFN2 , "w" , zipfile .ZIP_STORED ) as zipfp :
356+ zipfp .write (TESTFN , TESTFN )
357+ with open (TESTFN2 , 'a' ) as f :
358+ f .write ("\r \n \00 \00 \00 " )
359+ with zipfile .ZipFile (TESTFN2 , "r" ) as zipfp :
360+ self .assertIsInstance (zipfp , zipfile .ZipFile )
361+
362+ def test_ignores_stuff_appended_past_comments (self ):
363+ with zipfile .ZipFile (TESTFN2 , "w" , zipfile .ZIP_STORED ) as zipfp :
364+ zipfp .comment = b"this is a comment"
365+ zipfp .write (TESTFN , TESTFN )
366+ with open (TESTFN2 , 'a' ) as f :
367+ f .write ("abcdef\r \n " )
368+ with zipfile .ZipFile (TESTFN2 , "r" ) as zipfp :
369+ self .assertIsInstance (zipfp , zipfile .ZipFile )
370+ self .assertEqual (zipfp .comment , b"this is a comment" )
371+
354372 def test_write_default_name (self ):
355373 """Check that calling ZipFile.write without arcname specified
356374 produces the expected result."""
0 commit comments