Skip to content

Commit f56b0d2

Browse files
gorhillmarijnh
authored andcommitted
[merge addon] Fix edge case arising when diff'ing empty strings
The merge view will incorrectly show a "Revert chunk" arrow when the text on both sides of the view are the empty string. The getChunks() helper is not prepared to deal with an empty diff array. The getDiff() helper returns an empty diff array when both strings to compare are empty, as the only diff item returned by diff_match_patch, `[0, ""]`, is removed as a result of the diff entry containing an empty string. The chosen (trivial) fix is to simply check for the empty diff array case at the top of getChunks().
1 parent 6fca1c7 commit f56b0d2

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

addon/merge/merge.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@
664664

665665
function getChunks(diff) {
666666
var chunks = [];
667+
if (!diff.length) return chunks;
667668
var startEdit = 0, startOrig = 0;
668669
var edit = Pos(0, 0), orig = Pos(0, 0);
669670
for (var i = 0; i < diff.length; ++i) {

0 commit comments

Comments
 (0)