Skip to content

Commit 4f077a0

Browse files
committed
Removed special case tags behaviour
While inserting the <ins> or <del> tags we looked at a list of special tags, and tried to also wrap those in extra <ins> or <del> tags. This behaviour is inherited from the library that this library is based on, and seems to have some bugs in it. We got some reports in GitHub about this, and intially I tried to fix the feature. After realizing the use-case for this is not documented, not in this library or the source library, and the use-case for it is vague, and it being more trouble then it's worth, maybe its best to just completely remove it, reducing the code complexity in the process and also fixing the issues all at the same time.
1 parent 2081bf8 commit 4f077a0

File tree

1 file changed

+25
-54
lines changed

1 file changed

+25
-54
lines changed

lib/Caxy/HtmlDiff/HtmlDiff.php

Lines changed: 25 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -530,73 +530,44 @@ protected function findIsolatedDiffTagsInOld($operation, $posInNew)
530530
*/
531531
protected function insertTag($tag, $cssClass, &$words)
532532
{
533-
while (true) {
534-
if (count($words) === 0) {
535-
break;
536-
}
537-
533+
while (count($words) > 0) {
538534
$nonTags = $this->extractConsecutiveWords($words, 'noTag');
539535

540-
$specialCaseTagInjection = '';
541-
$specialCaseTagInjectionIsBefore = false;
542-
543-
if (count($nonTags) !== 0) {
536+
if (count($nonTags) > 0) {
544537
$this->content .= $this->wrapText(implode('', $nonTags), $tag, $cssClass);
545-
} else {
546-
$firstOrDefault = false;
547-
foreach ($this->config->getSpecialCaseOpeningTags() as $x) {
548-
if (preg_match($x, $words[ 0 ])) {
549-
$firstOrDefault = $x;
550-
break;
551-
}
552-
}
553-
if ($firstOrDefault) {
554-
$specialCaseTagInjection = '<ins class="mod">';
555-
if ($tag === 'del') {
556-
unset($words[ 0 ]);
557-
}
558-
} elseif (array_search($words[ 0 ], $this->config->getSpecialCaseClosingTags()) !== false) {
559-
$specialCaseTagInjection = '</ins>';
560-
$specialCaseTagInjectionIsBefore = true;
561-
if ($tag === 'del') {
562-
unset($words[ 0 ]);
563-
}
564-
}
565538
}
566-
if (count($words) == 0 && $this->stringUtil->strlen($specialCaseTagInjection) == 0) {
539+
540+
if (count($words) === 0) {
567541
break;
568542
}
569-
if ($specialCaseTagInjectionIsBefore) {
570-
$this->content .= $specialCaseTagInjection . implode('', $this->extractConsecutiveWords($words, 'tag'));
571-
} else {
572-
$workTag = $this->extractConsecutiveWords($words, 'tag');
573543

574-
if (
575-
isset($workTag[0]) === true &&
576-
$this->isOpeningTag($workTag[0]) === true &&
577-
$this->isClosingTag($workTag[0]) === false
578-
) {
579-
if ($this->stringUtil->strpos($workTag[0], 'class=')) {
580-
$workTag[0] = str_replace('class="', 'class="diffmod ', $workTag[0]);
581-
} else {
582-
$isSelfClosing = $this->stringUtil->strpos($workTag[0], '/>') !== false;
544+
$workTag = $this->extractConsecutiveWords($words, 'tag');
545+
546+
if (
547+
isset($workTag[0]) === true &&
548+
$this->isOpeningTag($workTag[0]) === true &&
549+
$this->isClosingTag($workTag[0]) === false
550+
) {
551+
if ($this->stringUtil->strpos($workTag[0], 'class=')) {
552+
$workTag[0] = str_replace('class="', 'class="diffmod ', $workTag[0]);
553+
} else {
554+
$isSelfClosing = $this->stringUtil->strpos($workTag[0], '/>') !== false;
583555

584-
if ($isSelfClosing === true) {
585-
$workTag[0] = str_replace('/>', ' class="diffmod" />', $workTag[0]);
586-
} else {
587-
$workTag[0] = str_replace('>', ' class="diffmod">', $workTag[0]);
588-
}
556+
if ($isSelfClosing === true) {
557+
$workTag[0] = str_replace('/>', ' class="diffmod" />', $workTag[0]);
558+
} else {
559+
$workTag[0] = str_replace('>', ' class="diffmod">', $workTag[0]);
589560
}
590561
}
562+
}
591563

592-
$appendContent = implode('', $workTag) . $specialCaseTagInjection;
564+
$appendContent = implode('', $workTag);
593565

594-
if (isset($workTag[0]) === true && $this->stringUtil->stripos($workTag[0], '<img') !== false) {
595-
$appendContent = $this->wrapText($appendContent, $tag, $cssClass);
596-
}
597-
598-
$this->content .= $appendContent;
566+
if (isset($workTag[0]) === true && $this->stringUtil->stripos($workTag[0], '<img') !== false) {
567+
$appendContent = $this->wrapText($appendContent, $tag, $cssClass);
599568
}
569+
570+
$this->content .= $appendContent;
600571
}
601572
}
602573

0 commit comments

Comments
 (0)