Skip to content

Commit 9a741a4

Browse files
committed
JavaScript: Fix known-broken diffs from objective-c
1 parent df21753 commit 9a741a4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

javascript/diff_match_patch_uncompressed.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,13 @@ diff_match_patch.prototype.decodeURI = function(text) {
15121512
throw new URIError('URI malformed');
15131513
}
15141514

1515-
return decoded;
1515+
// some objective-c versions of the library produced patches with
1516+
// (null) in the place where surrogates were split across diff
1517+
// boundaries. if we leave those in we'll be stuck with a
1518+
// high-surrogate (null) low-surrogate pattern that will break
1519+
// deeper in the library or consumping application. we'll "fix"
1520+
// these by dropping the (null) and re-joining the surrogate halves
1521+
return decoded.replace(/([\uD800-\uDBFF])\(null\)([\uDC00-\uDFFF])/g, "$1$2");
15161522
}
15171523
};
15181524

javascript/tests/diff_match_patch_test.js

+9
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,15 @@ function testDiffDelta() {
605605
assertEquals('Swap surrogate pair', 'crashed');
606606
}
607607

608+
try {
609+
assertEquivalent(
610+
dmp.diff_fromDelta('', '+%ED%A0%BC%28null%29%ED%B5%B0'),
611+
[[DIFF_INSERT, '\ud83c\udd70']]
612+
);
613+
} catch ( e ) {
614+
assertEquals('Invalid diff from objective-c with (null) string' );
615+
}
616+
608617
// Empty diff groups
609618
assertEquivalent(
610619
dmp.diff_toDelta([[DIFF_EQUAL, 'abcdef'], [DIFF_DELETE, ''], [DIFF_INSERT, 'ghijk']]),

0 commit comments

Comments
 (0)