This repository was archived by the owner on Aug 5, 2024. It is now read-only.
File tree 2 files changed +17
-2
lines changed
src/name/fraser/neil/plaintext
tests/name/fraser/neil/plaintext
2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -1507,7 +1507,7 @@ private int digit16(char b) throws IllegalArgumentException {
1507
1507
1508
1508
private String decodeURI (String text ) throws IllegalArgumentException {
1509
1509
int i = 0 ;
1510
- StringBuffer decoded = new StringBuffer ( "" );
1510
+ StringBuilder decoded = new StringBuilder ( text . length () );
1511
1511
1512
1512
while (i < text .length ()) {
1513
1513
if (text .charAt (i ) != '%' ) {
@@ -1576,7 +1576,16 @@ private String decodeURI(String text) throws IllegalArgumentException {
1576
1576
throw new IllegalArgumentException ();
1577
1577
}
1578
1578
1579
- return decoded .toString ();
1579
+ // some objective-c versions of the library produced patches with
1580
+ // (null) in the place where surrogates were split across diff
1581
+ // boundaries. if we leave those in we'll be stuck with a
1582
+ // high-surrogate (null) low-surrogate pattern that will break
1583
+ // deeper in the library or consuming application. we'll "fix"
1584
+ // these by dropping the (null) and re-joining the surrogate halves
1585
+ return decoded .toString ().replaceAll (
1586
+ "([\\ uD800-\\ uDBFF])\\ (null\\ )([\\ uDC00-\\ uDFFF])" ,
1587
+ "$1$2"
1588
+ );
1580
1589
}
1581
1590
1582
1591
/**
Original file line number Diff line number Diff line change @@ -460,6 +460,12 @@ public static void testDiffDelta() {
460
460
dmp .diff_toDelta (dmp .diff_fromDelta ("\ud83c \udd70 " , "=1\t -1\t +%ED%B5%B1" ))
461
461
);
462
462
463
+ assertEquals (
464
+ "diff_fromDelta: Invalid diff from objective-c with (null) string" ,
465
+ diffList (new Diff (INSERT , "\ud83c \udd70 " )),
466
+ dmp .diff_fromDelta ("" , "+%ED%A0%BC%28null%29%ED%B5%B0" )
467
+ );
468
+
463
469
// Verify pool of unchanged characters.
464
470
diffs = diffList (new Diff (INSERT , "A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # " ));
465
471
String text2 = dmp .diff_text2 (diffs );
You can’t perform that action at this time.
0 commit comments