diff-match-patch icon indicating copy to clipboard operation
diff-match-patch copied to clipboard

Fix string comparison

Open ranvis opened this issue 5 years ago • 1 comments

Fix string comparison to use operator === as PHP tries numeric comparison whenever possible for operator ==:

assert('0' == '00');
assert(null == '');

use DiffMatchPatch\Diff;
$dmp = new Diff();
var_dump($dmp->main('1', '00000000000000001', false)->getChanges());
// array(1) {
//   [0]=>
//   array(2) {
//     [0]=>
//     int(0)
//     [1]=>
//     string(1) "1"
//   }
// }

ranvis avatar Feb 21 '20 23:02 ranvis

Any update on this? We ran into the same or at least a similar issue today. Creating a patch between the values string(1) "0" and string(1) "1" hangs infinitely.

thirsch avatar Jan 25 '24 10:01 thirsch