@@ -282,6 +282,29 @@ def test_make_file_usascii_charset_with_nonascii_input(self):
282282 self .assertIn ('content="text/html; charset=us-ascii"' , output )
283283 self .assertIn ('ımplıcıt' , output )
284284
285+ def test_strip_trailing_newlines_before_diff (self ):
286+ # characterization test for the current buggy behavior
287+ # see: gh-71896
288+ html_diff = difflib .HtmlDiff ()
289+ from_lines = [
290+ "Line 1: no newline after" ,
291+ "Line 2: one newline after\n " ,
292+ "Line 3: several newlines after\n \n \n \n \n " ,
293+ ]
294+ to_lines = [
295+ "Line 1: no newline after" ,
296+ "Line 2: one newline after" , # actually no \n
297+ "Line 3: several newlines after" , # actually no \n
298+ ]
299+ output = html_diff .make_table (from_lines , to_lines )
300+ # we (currently) expect no line change, so all equal
301+ self .assertNotIn ('class="diff_add"' , output )
302+ self .assertNotIn ('class="diff_chg"' , output )
303+ self .assertNotIn ('class="diff_sub"' , output )
304+ self .assertEqual (output .count ('>Line 1: no newline after<' ), 2 )
305+ self .assertEqual (output .count ('>Line 2: one newline after<' ), 2 )
306+ self .assertEqual (output .count ('>Line 3: several newlines after<' ), 2 )
307+
285308class TestDiffer (unittest .TestCase ):
286309 def test_close_matches_aligned (self ):
287310 # Of the 4 closely matching pairs, we want 1 to match with 3,
0 commit comments