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