-
-
Notifications
You must be signed in to change notification settings - Fork 201
Open
Description
When using DiffRowGenerator
with inlineDiffByWord(false)
for character-level diff, the marked differences are not correctly aligned. Specifically, when comparing "aaaab"and "bbbbb", the output is:
Old: aaaab(correct)
New: bbbbb(incorrect, expected bbbbb)
This suggests that the diff algorithm is not strictly aligning changes by character position.
Demo code:
import com.github.difflib.DiffUtils;
import com.github.difflib.algorithm.myers.MyersDiff;
import com.github.difflib.text.DiffRow;
import com.github.difflib.text.DiffRowGenerator;
import java.util.List;
public class DiffExample {
public static void main(String[] args) {
DiffRowGenerator generator = DiffRowGenerator.create()
.showInlineDiffs(true)
.inlineDiffByWord(false)
.ignoreWhiteSpaces(false)
.oldTag(f -> "~")
.newTag(f -> "**")
.build();
List<DiffRow> rows = generator.generateDiffRows(
List.of("aaaab"),
List.of("bbbbb")
);
System.out.println("Old: " + rows.get(0).getOldLine()); // Actual: ~aaaa~b
System.out.println("New: " + rows.get(0).getNewLine()); // Actual: b**bbbb** (Expected: **bbbb**b)
}
}
Metadata
Metadata
Assignees
Labels
No labels