Skip to content

Commit d9948ae

Browse files
committed
fix : fix broken prefix and suffix diffs generation inside _addContext_
1 parent e3cdf5d commit d9948ae

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

javascript/diff_match_patch_uncompressed.js

+11
Original file line numberDiff line numberDiff line change
@@ -1776,12 +1776,23 @@ diff_match_patch.prototype.patch_addContext_ = function(patch, text) {
17761776

17771777
// Add the prefix.
17781778
var prefix = text.substring(patch.start2 - padding, patch.start2);
1779+
1780+
if(this.isLowSurrogate(prefix[0])) {
1781+
prefix = text.substring(patch.start2 - padding - 1 , patch.start2);
1782+
}
1783+
17791784
if (prefix) {
17801785
patch.diffs.unshift(new diff_match_patch.Diff(DIFF_EQUAL, prefix));
17811786
}
17821787
// Add the suffix.
17831788
var suffix = text.substring(patch.start2 + patch.length1,
17841789
patch.start2 + patch.length1 + padding);
1790+
1791+
if(this.isHighSurrogate(suffix[suffix.length-1])) {
1792+
suffix = text.substring(patch.start2 + patch.length1,
1793+
patch.start2 + patch.length1 + padding + 1);
1794+
}
1795+
17851796
if (suffix) {
17861797
patch.diffs.push(new diff_match_patch.Diff(DIFF_EQUAL, suffix));
17871798
}

0 commit comments

Comments
 (0)