Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imperfect match with deletions in the diff will cause incorrect patch (C#) #87

Open
derammo opened this issue Mar 21, 2020 · 1 comment

Comments

@derammo
Copy link

derammo commented Mar 21, 2020

Here is an example that fails:

    private static void TestBrokenImperfectMatch()
    {
        string referenceInput = "diff matching patching";
        string referenceOutput = "diff match patch";
        string imperfectInput = "diff matching pthing";
        diff_match_patch googleDiff = new diff_match_patch();
        List<Diff> diffs = googleDiff.diff_main(referenceInput, referenceOutput);
        googleDiff.diff_cleanupSemantic(diffs);
        List<Patch> patches = googleDiff.patch_make(diffs);
        Debug.WriteLine(googleDiff.patch_toText(patches));
        string patched = (string)googleDiff.patch_apply(patches, imperfectInput)[0];
        Debug.WriteLine(patched);
        Debug.Assert(patched == "diff match pth");
    }

The root cause is that, while processing the imperfect match, the reference text and actual text (text1 and text2) offsets are inaccurate after the first deletion ("a") and so the index calculation gets the wrong result for the removal of the second "ing". It ends up removing "ng". I could not fix it while still using index2 as both the offset into the actual string being edited ("text") and into the unedited input ("text2") so I introduced an offset between the two.

A fix is here HeliosVirtualCockpit@0f5aa41 but I won't make a PR because I don't have code for the other languages and I have basically no test coverage.

@derammo
Copy link
Author

derammo commented Jul 14, 2020

Looks like this repo is dead / unsupported at this point. I will just work in my fork forever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant