google / diff-match-patch

Diff Match Patch is a high-performance library in multiple languages that manipulates plain text.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Diff is calculating very wrong results

ogil7190 opened this issue · comments

While using the library, I have noticed that there is a serious problem with text diff, a very simple example is not working fine, looking at the code developed by google, it was hard for me to believe that, why it is not working fine. If you look at the screenshot below you will see that it is almost correct, but very wrong in results.

It is saying i have added certain lines, which were already a part of the original and input string.
Second, it has seriously messed up the order, in which they occur.

CAN ANYONE HELP HERE?

image

Hi @ogil7190 - I'm seeing what looks like accurate output, so maybe you could share what you see as being wrong in the output specifically.

It's not showing that you've added lines at all, for example, only that the last eight words and additional u letter are not present in the input after removing the rest of the first paragraph.

The diffs are a recipe to move from the first version to the second, and there's no guarantee that what it produces is going to be the same "edit script" you expect it to be. For some reason it recognized the long paragraph removal as a single deletion and added back in the part where the y changed into a u. It could have also deleted the y, inserted a u, kept the rest of the sentence, then deleted everything else.

The important point to note though is that the patch should generate the second text when applied to the first, which in this case it looks like it does.