kpdecker / jsdiff

A javascript text differencing implementation.
BSD 3-Clause "New" or "Revised" License
7.92k stars 496 forks source link

Fix handling of EOF in createPatch #535

Closed ExplodingCabbage closed 1 month ago

ExplodingCabbage commented 1 month ago

Fixes https://github.com/kpdecker/jsdiff/issues/531.

But also rips out the ability to pass newlineIsToken to createPatch et al, because my changes here broke the tests (that @oBusk had added in https://github.com/kpdecker/jsdiff/pull/345) for that feature and when I dug into it I realised - like I think @oBusk kinda implies in that PR description - that the whole feature is kinda broken, since it causes line ending changes to get falsely represented as deletions and insertions of entire blank lines in the patch.

(I suspect @Kiougar didn't consider the newlineIsToken option specifically back in 2016 when he wrote https://github.com/kpdecker/jsdiff/pull/153, and was probably thinking primarily about options like ignoreWhitespace which do make sense to pass to patch functions.)