@@ -1019,3 +1019,41 @@ func TestApplyFile_PreservesExactBytes(t *testing.T) {
10191019 require .NoError (t , err )
10201020 assert .True (t , bytes .Equal (files .out , applied ))
10211021}
1022+
1023+ // blankTrailingContextFixture provides a hunk inserting lines between two
1024+ // structural blocks where the trailing context line is blank. markEOFMarkers
1025+ // previously flagged any blank context line at the hunk's count boundary as
1026+ // an EOF marker, causing it to mismatch a real mid-file blank line in source.
1027+ var blankTrailingContextFixture = struct {
1028+ original []byte
1029+ target []byte
1030+ }{
1031+ original : []byte ("class Foo {\n void a() {}\n \n void b() {}\n \n void c() {}\n }\n " ),
1032+ target : []byte ("class Foo {\n void a() {}\n \n void b() {}\n \n void inserted() {}\n \n void c() {}\n }\n " ),
1033+ }
1034+
1035+ // TestApplyFile_BlankTrailingContextMidFile is a regression test for the
1036+ // fixture above against the direct apply path.
1037+ func TestApplyFile_BlankTrailingContextMidFile (t * testing.T ) {
1038+ t .Parallel ()
1039+
1040+ f := blankTrailingContextFixture
1041+ patch := buildPatchWithContext (t , "Foo.java" , f .original , f .target , 3 )
1042+ applied , err := ApplyFile (f .original , patch )
1043+ require .NoError (t , err )
1044+ assert .Equal (t , f .target , applied )
1045+ }
1046+
1047+ // TestApplyFile_BlankTrailingContextWithConflicts mirrors the regression test
1048+ // above against the merge mode used by ApplyFileWithConflicts. The bug
1049+ // surfaced as a spurious conflict on a freshly generated file because the
1050+ // hunk's trailing blank context was misidentified as an EOF marker.
1051+ func TestApplyFile_BlankTrailingContextWithConflicts (t * testing.T ) {
1052+ t .Parallel ()
1053+
1054+ f := blankTrailingContextFixture
1055+ patch := buildPatchWithContext (t , "Foo.java" , f .original , f .target , 3 )
1056+ applied , err := ApplyFileWithConflicts (f .original , patch )
1057+ require .NoError (t , err )
1058+ assert .Equal (t , f .target , applied )
1059+ }
0 commit comments