Skip to content

Commit

Permalink
Fix issue with HtmlDiff matching skipping some single word matches
Browse files Browse the repository at this point in the history
  • Loading branch information
jschroed91 committed Feb 2, 2016
1 parent 36467f2 commit 4fb7b52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/Caxy/HtmlDiff/AbstractDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ protected function convertHtmlToListOfWords($characterString)
}
$current_word = "<";
$mode = 'tag';
} elseif ( preg_match( "[^\s]", $character ) > 0 ) {
if ($current_word != '') {
} elseif (preg_match("/\s/", $character)) {
if ($current_word !== '') {
$words[] = $current_word;
}
$current_word = $character;
$current_word = preg_replace('/\s+/S', ' ', $character);
$mode = 'whitespace';
} else {
if (
Expand Down Expand Up @@ -259,13 +259,14 @@ protected function convertHtmlToListOfWords($characterString)
break;
case 'whitespace':
if ( $this->isStartOfTag( $character ) ) {
if ($current_word != '') {
if ($current_word !== '') {
$words[] = $current_word;
}
$current_word = "<";
$mode = 'tag';
} elseif ( preg_match( "[^\s]", $character ) ) {
} elseif ( preg_match( "/\s/", $character ) ) {
$current_word .= $character;
$current_word = preg_replace('/\s+/S', ' ', $current_word);
} else {
if ($current_word != '') {
$words[] = $current_word;
Expand Down
11 changes: 10 additions & 1 deletion lib/Caxy/HtmlDiff/HtmlDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,16 @@ protected function findMatch($startInOld, $endInOld, $startInNew, $endInNew)
}
$newMatchLength = ( isset( $matchLengthAt[ $indexInNew - 1 ] ) ? $matchLengthAt[ $indexInNew - 1 ] : 0 ) + 1;
$newMatchLengthAt[ $indexInNew ] = $newMatchLength;
if ($newMatchLength > $bestMatchSize) {
if ($newMatchLength > $bestMatchSize ||
(
$this->isGroupDiffs() &&
$bestMatchSize > 0 &&
preg_match(
'/^\s+$/',
implode('', array_slice($this->oldWords, $bestMatchInOld, $bestMatchSize))
)
)
) {
$bestMatchInOld = $indexInOld - $newMatchLength + 1;
$bestMatchInNew = $indexInNew - $newMatchLength + 1;
$bestMatchSize = $newMatchLength;
Expand Down

0 comments on commit 4fb7b52

Please sign in to comment.