Skip to content

Fix reverse overlap handling in line mode - #22

Open
gugglegum wants to merge 1 commit into
yetanotherape:masterfrom
gugglegum:master
Open

Fix reverse overlap handling in line mode#22
gugglegum wants to merge 1 commit into
yetanotherape:masterfrom
gugglegum:master

Conversation

@gugglegum

Copy link
Copy Markdown

Summary

Fix incorrect diff output produced by line-mode when semantic cleanup detects a reverse overlap with unequal prefix and overlap lengths.

The bug could cause the destination reconstructed from the returned diff operations to differ from the destination passed to diff_main().

Root cause

For a reverse overlap, the overlapping suffix of the insertion is moved into an EQUAL operation. The remaining insertion must therefore exclude that suffix.

The PHP implementation used the overlap length as the retained prefix length:

mb_substr($insertion, 0, $overlap_length2)

It should remove the overlap from the end:

mb_substr($insertion, 0, -$overlap_length2)

The existing reverse-overlap test did not expose the problem because its insertion length was exactly twice the overlap length, making both calculations return the same substring.

Test

Added a minimal line-mode regression test that verifies both projections of the generated diff:

  • equalities and deletions reconstruct the source;
  • equalities and insertions reconstruct the destination.

Before the fix, the destination assertion fails because part of the overlap is duplicated.

Full test suite:

OK (46 tests, 211 assertions)

@yetanotherape

Copy link
Copy Markdown
Owner

Hi Paul, could you please provide a test case showing the issue?

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

Successfully merging this pull request may close these issues.

2 participants