Fixing bug in HTML diff when the word '0' is encountered. Thanks siebrand for reporting
[lhc/web/wiklou.git] / includes / Diff.php
index 3aececf..23b2b9e 100644 (file)
@@ -87,8 +87,12 @@ class WikiDiff3 {
                $this->from = $newFromIndex = $this->to = $newToIndex = array();
 
                //remove tokens not in both sequences
-               $shared = array_fill_keys($from, false);
-               foreach($to as $index => $el) {
+               $shared = array();
+               foreach( $from as $key ) {
+                       $shared[$key] = false;
+               }
+
+               foreach($to as $index => &$el) {
                        if(array_key_exists($el, $shared)) {
                                //keep it
                                $this->to[] = $el;
@@ -96,7 +100,7 @@ class WikiDiff3 {
                                $newToIndex[] = $index;
                        }
                }
-               foreach($from as $index => $el) {
+               foreach($from as $index => &$el) {
                        if($shared[$el]) {
                                //keep it
                                $this->from[] = $el;
@@ -155,12 +159,12 @@ class WikiDiff3 {
 
                $this->length += $i + $j - 1;
 
-               foreach($this->removed as $key => $removed_elem) {
+               foreach($this->removed as $key => &$removed_elem) {
                        if(!$removed_elem) {
                                $removed[$newFromIndex[$key]] = false;
                        }
                }
-               foreach($this->added as $key => $added_elem) {
+               foreach($this->added as $key => &$added_elem) {
                        if(!$added_elem) {
                                $added[$newToIndex[$key]] = false;
                        }
@@ -287,7 +291,7 @@ class WikiDiff3 {
                $V0[$limit_plus_1] = 0;
                $V1[$limit_min_1] = $N;
                $limit = min($this->maxDifferences, ceil(($N + $M ) / 2));
-                       
+
                if (($delta & 1) == 1) {
                        for ($d = 0; $d <= $limit; ++$d) {
                                $start_diag = max($value_to_add_forward + $start_forward, -$d);
@@ -296,7 +300,7 @@ class WikiDiff3 {
 
                                // compute forward furthest reaching paths
                                for ($k = $start_diag; $k <= $end_diag; $k += 2) {
-                                       if ($k == -$d || ($k < $d 
+                                       if ($k == -$d || ($k < $d
                                                        && $V0[$limit_min_1 + $k] < $V0[$limit_plus_1 + $k])) {
                                                $x = $V0[$limit_plus_1 + $k];
                                        } else {
@@ -448,7 +452,7 @@ class WikiDiff3 {
                $snake0 = $bottoml1 + $most_progress[0];
                $snake1 = $bottoml2 + $most_progress[1];
                $snake2 = 0;
-               wfDebug('Computing the LCS is too expensive. Using a heuristic.\n');
+               wfDebug("Computing the LCS is too expensive. Using a heuristic.\n");
                $this->heuristicUsed = true;
                return 5; /*
                * HACK: since we didn't really finish the LCS computation