kpdecker / jsdiff

A javascript text differencing implementation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Line diff apply giving extra line in the end when source is empty string

prabhat-awasthi-3697 opened this issue · comments

Case 1: When extra \n is added by appyPatch

source : "" and destination: "abcd"

above combination will create the patch as --> "@@ -1,0 +1,1 @@\n+abcd\n"

applyPatch("", ["@@ -1,0 +1,1 @@\n+abcd\n"]) results in --> "abcd\n" (This extra \n is added)

Case 2: When \n is removed by applyPatch

source: "" and destination: "abcd\n"

above combination will still result in patch --> "@@ -1,0 +1,1 @@\n+abcd\n"

Facing similar issue related to this.
Extra new line character is added on patching anything to empty string.

Apparently it assumes POSIX lines https://stackoverflow.com/a/729795 and if it isn't comparing one set of lines to another it fails. I would be interested to see a bug report where everything involved ends with a newline.

I think UNIX considers an empty file to be text so that's an issue, sure.