This repository was archived by the owner on Aug 5, 2024. It is now read-only.
File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -1492,8 +1492,24 @@ - (NSString *)diff_decodeURIWithText:(NSString *)percentEncoded
1492
1492
@catch (NSException *e) {
1493
1493
return nil ;
1494
1494
}
1495
-
1496
- return [NSString stringWithCharacters: decoded length: output];
1495
+
1496
+ // some objective-c versions of the library produced patches with
1497
+ // (null) in the place where surrogates were split across diff
1498
+ // boundaries. if we leave those in we'll be stuck with a
1499
+ // high-surrogate (null) low-surrogate pattern that will break
1500
+ // deeper in the library or consumping application. we'll "fix"
1501
+ // these by dropping the (null) and re-joining the surrogate halves
1502
+ NSString *result = [NSString stringWithCharacters: decoded length: output];
1503
+ NSRegularExpression *replacer = [NSRegularExpression
1504
+ regularExpressionWithPattern: @" ([\\ x{D800}-\\ x{DBFF}])\\ (null\\ )([\\ x{DC00}-\\ x{DFFF}])"
1505
+ options: 0
1506
+ error: nil ];
1507
+
1508
+ return [replacer
1509
+ stringByReplacingMatchesInString: result
1510
+ options: 0
1511
+ range: NSMakeRange (0 , [result length ])
1512
+ withTemplate: @" $1$2" ];
1497
1513
}
1498
1514
1499
1515
/* *
Original file line number Diff line number Diff line change @@ -814,6 +814,10 @@ - (void)test_diff_deltaTest {
814
814
[Diff diffWithOperation: DIFF_INSERT andText: [NSString stringWithFormat: @" %C " , 0xdd71 ]],
815
815
nil ])]);
816
816
817
+ // Invalid diff from objective-c with (null) string
818
+ XCTAssertEqualObjects ([dmp diff_fromDeltaWithText: @" " andDelta: @" +%E D%A 0%BC%28n ull%29% ED%B5%B0" error: nil ],
819
+ ([NSMutableArray arrayWithObjects: [Diff diffWithOperation: DIFF_INSERT andText: @" 🅰" ],nil ]));
820
+
817
821
// Verify pool of unchanged characters.
818
822
diffs = [NSMutableArray arrayWithObject:
819
823
[Diff diffWithOperation: DIFF_INSERT andText: @" A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # " ]];
You can’t perform that action at this time.
0 commit comments