Skip to content

Commit 0fba40f

Browse files
authored
Fix to handle encodeURI exception
it might get Malformed URI exception when there is a lone surrogate inside a string
1 parent 5699ebe commit 0fba40f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,11 @@ diff_match_patch.prototype.diff_toDelta = function(diffs) {
13231323
for (var x = 0; x < diffs.length; x++) {
13241324
switch (diffs[x][0]) {
13251325
case DIFF_INSERT:
1326-
text[x] = '+' + encodeURI(diffs[x][1]);
1326+
try {
1327+
text[x] = '+' + encodeURI(diffs[x][1]);
1328+
} catch (ex) {
1329+
text[x] = '+' + diffs[x][1];
1330+
}
13271331
break;
13281332
case DIFF_DELETE:
13291333
text[x] = '-' + diffs[x][1].length;
@@ -2179,7 +2183,11 @@ diff_match_patch.patch_obj.prototype.toString = function() {
21792183
op = ' ';
21802184
break;
21812185
}
2182-
text[x + 1] = op + encodeURI(this.diffs[x][1]) + '\n';
2186+
try {
2187+
text[x + 1] = op + encodeURI(this.diffs[x][1]) + '\n';
2188+
} catch (ex) {
2189+
text[x + 1] = op + this.diffs[x][1] + '\n';
2190+
}
21832191
}
21842192
return text.join('').replace(/%20/g, ' ');
21852193
};

0 commit comments

Comments
 (0)