Skip to content

Commit e9b4386

Browse files
authored
Bugfix Adding class crippled HTML in selfclosing tags
Bugfix Adding class crippled HTML in self-closing tags
2 parents 4c142a5 + 8544d39 commit e9b4386

File tree

5 files changed

+31
-29
lines changed

5 files changed

+31
-29
lines changed

lib/Caxy/HtmlDiff/HtmlDiff.php

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ protected function findIsolatedDiffTagsInOld($operation, $posInNew)
534534
protected function insertTag($tag, $cssClass, &$words)
535535
{
536536
while (true) {
537-
if (count($words) == 0) {
537+
if (count($words) === 0) {
538538
break;
539539
}
540540

@@ -556,13 +556,13 @@ protected function insertTag($tag, $cssClass, &$words)
556556
}
557557
if ($firstOrDefault) {
558558
$specialCaseTagInjection = '<ins class="mod">';
559-
if ($tag == 'del') {
559+
if ($tag === 'del') {
560560
unset($words[ 0 ]);
561561
}
562562
} elseif (array_search($words[ 0 ], $this->config->getSpecialCaseClosingTags()) !== false) {
563563
$specialCaseTagInjection = '</ins>';
564564
$specialCaseTagInjectionIsBefore = true;
565-
if ($tag == 'del') {
565+
if ($tag === 'del') {
566566
unset($words[ 0 ]);
567567
}
568568
}
@@ -571,22 +571,34 @@ protected function insertTag($tag, $cssClass, &$words)
571571
break;
572572
}
573573
if ($specialCaseTagInjectionIsBefore) {
574-
$this->content .= $specialCaseTagInjection.implode('', $this->extractConsecutiveWords($words, 'tag'));
574+
$this->content .= $specialCaseTagInjection . implode('', $this->extractConsecutiveWords($words, 'tag'));
575575
} else {
576576
$workTag = $this->extractConsecutiveWords($words, 'tag');
577-
if (isset($workTag[ 0 ]) && $this->isOpeningTag($workTag[ 0 ]) && !$this->isClosingTag($workTag[ 0 ])) {
578-
if ($this->stringUtil->strpos($workTag[ 0 ], 'class=')) {
579-
$workTag[ 0 ] = str_replace('class="', 'class="diffmod ', $workTag[ 0 ]);
580-
$workTag[ 0 ] = str_replace("class='", 'class="diffmod ', $workTag[ 0 ]);
577+
578+
if (
579+
isset($workTag[0]) === true &&
580+
$this->isOpeningTag($workTag[0]) === true &&
581+
$this->isClosingTag($workTag[0]) === false
582+
) {
583+
if ($this->stringUtil->strpos($workTag[0], 'class=')) {
584+
$workTag[0] = str_replace('class="', 'class="diffmod ', $workTag[0]);
581585
} else {
582-
$workTag[ 0 ] = str_replace('>', ' class="diffmod">', $workTag[ 0 ]);
586+
$isSelfClosing = $this->stringUtil->strpos($workTag[0], '/>') !== false;
587+
588+
if ($isSelfClosing === true) {
589+
$workTag[0] = str_replace('/>', ' class="diffmod" />', $workTag[0]);
590+
} else {
591+
$workTag[0] = str_replace('>', ' class="diffmod">', $workTag[0]);
592+
}
583593
}
584594
}
585595

586-
$appendContent = implode('', $workTag).$specialCaseTagInjection;
587-
if (isset($workTag[0]) && false !== $this->stringUtil->stripos($workTag[0], '<img')) {
596+
$appendContent = implode('', $workTag) . $specialCaseTagInjection;
597+
598+
if (isset($workTag[0]) === true && $this->stringUtil->stripos($workTag[0], '<img') !== false) {
588599
$appendContent = $this->wrapText($appendContent, $tag, $cssClass);
589600
}
601+
590602
$this->content .= $appendContent;
591603
}
592604
}
@@ -666,24 +678,14 @@ protected function isTag($item)
666678
return $this->isOpeningTag($item) || $this->isClosingTag($item);
667679
}
668680

669-
/**
670-
* @param string $item
671-
*
672-
* @return bool
673-
*/
674-
protected function isOpeningTag($item)
681+
protected function isOpeningTag($item) : bool
675682
{
676-
return preg_match('#<[^>]+>\\s*#iUu', $item);
683+
return preg_match('#<[^>]+>\\s*#iUu', $item) === 1;
677684
}
678685

679-
/**
680-
* @param string $item
681-
*
682-
* @return bool
683-
*/
684-
protected function isClosingTag($item)
686+
protected function isClosingTag($item) : bool
685687
{
686-
return preg_match('#</[^>]+>\\s*#iUu', $item);
688+
return preg_match('#</[^>]+>\\s*#iUu', $item) === 1;
687689
}
688690

689691
/**

tests/fixtures/HtmlDiff/new-paragraph-and-list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
</newText>
1717

1818
<expected>
19-
<em>Corridors</em> shall be fire-resistance rated in accordance with Table 1020.1. The <em>corridor</em> walls required to be fire-resistance rated shall comply with Section 708 for <em>fire partitions</em>.<br / class="diffmod"><br /><ins class="diffins">In addition, corridors in buildings of Types IIB, IIIB, and VB construction and assigned Risk Categories III and IV in Table 1604.5, other than Group I, shall have a fire resistance rating of not less than 1 hour where such buildings are any of the following:</ins><br / class="diffmod"><br /><ol><li><ins class="diffins">Assigned a Seismic Design Category C or D in Table 1613.3.5(1).</ins></li><ins class="diffins"> </ins><li class="diffmod"><ins class="diffins">Located in a flood hazard area established in accordance with Section 1612.3.</ins></li><ins class="diffins"> </ins><li class="diffmod"><ins class="diffins">Located in a </ins><em class="diffmod"><ins class="diffins">hurricane-prone regions</ins></em><ins class="diffins">.</ins></li><ins class="diffins"> </ins></ol><ul class="exception diff-list"><li class="normal"><strong>Exceptions:</strong><ol class="diff-list"><li class="normal">A <em>fire-resistance rating</em> is not required for <em>corridors</em> in an occupancy in Group E where each room that is used for instruction has not less than one door opening directly to the exterior and rooms for assembly purposes have not less than one-half of the required <em>means of egress</em> doors opening directly to the exterior. Exterior doors specified in this exception are required to be at ground level.</li><li class="normal">A <em>fire-resistance rating</em> is not required for <em>corridors</em> contained within a <em>dwelling unit</em> or <em>sleeping unit</em> in an occupancy in Groups I-1 and R.</li><li class="normal">A <em>fire-resistance rating</em> is not required for <em>corridors</em> in <em>open parking garages</em>.</li><li class="normal">A <em>fire-resistance rating</em> is not required for <em>corridors</em> in an occupancy in Group B that is a space requiring only a single <em>means of egress</em> complying with Section 1006.2.</li><li class="normal"><em>Corridors</em> adjacent to the <em>exterior walls</em> of buildings shall be permitted to have unprotected openings on unrated <em>exterior walls</em> where unrated walls are permitted by Table 602 and unprotected openings are permitted by Table 705.8.</li></ol></li></ul>
19+
<em>Corridors</em> shall be fire-resistance rated in accordance with Table 1020.1. The <em>corridor</em> walls required to be fire-resistance rated shall comply with Section 708 for <em>fire partitions</em>.<br class="diffmod" /><br /><ins class="diffins">In addition, corridors in buildings of Types IIB, IIIB, and VB construction and assigned Risk Categories III and IV in Table 1604.5, other than Group I, shall have a fire resistance rating of not less than 1 hour where such buildings are any of the following:</ins><br class="diffmod" /><br /><ol><li><ins class="diffins">Assigned a Seismic Design Category C or D in Table 1613.3.5(1).</ins></li><ins class="diffins"> </ins><li class="diffmod"><ins class="diffins">Located in a flood hazard area established in accordance with Section 1612.3.</ins></li><ins class="diffins"> </ins><li class="diffmod"><ins class="diffins">Located in a </ins><em class="diffmod"><ins class="diffins">hurricane-prone regions</ins></em><ins class="diffins">.</ins></li><ins class="diffins"> </ins></ol><ul class="exception diff-list"><li class="normal"><strong>Exceptions:</strong><ol class="diff-list"><li class="normal">A <em>fire-resistance rating</em> is not required for <em>corridors</em> in an occupancy in Group E where each room that is used for instruction has not less than one door opening directly to the exterior and rooms for assembly purposes have not less than one-half of the required <em>means of egress</em> doors opening directly to the exterior. Exterior doors specified in this exception are required to be at ground level.</li><li class="normal">A <em>fire-resistance rating</em> is not required for <em>corridors</em> contained within a <em>dwelling unit</em> or <em>sleeping unit</em> in an occupancy in Groups I-1 and R.</li><li class="normal">A <em>fire-resistance rating</em> is not required for <em>corridors</em> in <em>open parking garages</em>.</li><li class="normal">A <em>fire-resistance rating</em> is not required for <em>corridors</em> in an occupancy in Group B that is a space requiring only a single <em>means of egress</em> complying with Section 1006.2.</li><li class="normal"><em>Corridors</em> adjacent to the <em>exterior walls</em> of buildings shall be permitted to have unprotected openings on unrated <em>exterior walls</em> where unrated walls are permitted by Table 602 and unprotected openings are permitted by Table 705.8.</li></ol></li></ul>
2020
</expected>

tests/fixtures/HtmlDiff/override-4.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
</newText>
2525

2626
<expected>
27-
<em>Corridors</em> shall be fire-resistance rated in accordance with Table 1020.1<ins class="diffins"> and where applicable in Section 1020.1.1</ins>. The <em>corridor</em> walls required to be fire-resistance rated shall comply with Section 708 for <em>fire partitions</em>.<br /><br / class="diffmod"><del class="diffdel">In addition, corridors in buildings of Types IIB, IIIB, and VB construction and assigned Risk Categories III and IV in Table 1604.5, other than Group I, shall have a fire resistance rating of not less than 1 hour where such buildings are any of the following:</del><br / class="diffmod"><br /><ol><li><del class="diffdel">Assigned a Seismic Design Category C or D in Table 1613.3.5(1).</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">Located in a flood hazard area established in accordance with Section 1612.3.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">Located in a </del><em class="diffmod"><del class="diffdel">hurricane-prone regions</del></em><del class="diffdel">.</del></li><del class="diffdel"> </del></ol><ul class="exception diff-list"><li class="normal"><strong>Exceptions:</strong><ol class="diffmod"><li><del class="diffdel">A </del><em class="diffmod"><del class="diffdel">fire-resistance rating</del></em><del class="diffdel"> is not required for </del><em class="diffmod"><del class="diffdel">corridors</del></em><del class="diffdel"> in an occupancy in Group E where each room that is used for instruction has not less than one door opening directly to the exterior and rooms for assembly purposes have not less than one-half of the required </del><em class="diffmod"><del class="diffdel">means of egress</del></em><del class="diffdel"> doors opening directly to the exterior. Exterior doors specified in this exception are required to be at ground level.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">A </del><em class="diffmod"><del class="diffdel">fire-resistance rating</del></em><del class="diffdel"> is not required for </del><em class="diffmod"><del class="diffdel">corridors</del></em><del class="diffdel"> contained within a </del><em class="diffmod"><del class="diffdel">dwelling unit</del></em><del class="diffdel"> or </del><em class="diffmod"><del class="diffdel">sleeping unit</del></em><del class="diffdel"> in an occupancy in Groups I-1 and R.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">A </del><em class="diffmod"><del class="diffdel">fire-resistance rating</del></em><del class="diffdel"> is not required for </del><em class="diffmod"><del class="diffdel">corridors</del></em><del class="diffdel"> in </del><em class="diffmod"><del class="diffdel">open parking garages</del></em><del class="diffdel">.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">A </del><em class="diffmod"><del class="diffdel">fire-resistance rating</del></em><del class="diffdel"> is not required for </del><em class="diffmod"><del class="diffdel">corridors</del></em><del class="diffdel"> in an occupancy in Group B that is a space requiring only a single </del><em class="diffmod"><del class="diffdel">means of egress</del></em><del class="diffdel"> complying with Section 1006.2.</del></li><del class="diffdel"> </del><li class="diffmod"><em><del class="diffdel">Corridors</del></em><del class="diffdel"> adjacent to the </del><em class="diffmod"><del class="diffdel">exterior walls</del></em><del class="diffdel"> of buildings shall be permitted to have unprotected openings on unrated </del><em class="diffmod"><del class="diffdel">exterior walls</del></em><del class="diffdel"> where unrated walls are permitted by Table 602 and unprotected openings are permitted by Table 705.8.</del></li><del class="diffdel"> </del></ol></li><li class="normal new"><ins> <ol><li>A <em>fire-resistance rating</em> is not required for <em>corridors</em> in an occupancy in Group E where each room that is used for instruction has not less than one door opening directly to the exterior and rooms for assembly purposes have not less than one-half of the required <em>means of egress</em> doors opening directly to the exterior. Exterior doors specified in this exception are required to be at ground level.</li> <li>A <em>fire-resistance rating</em> is not required for <em>corridors</em> contained within a <em>dwelling unit</em> or <em>sleeping unit</em> in an occupancy in Groups I-1 and R.</li> <li>A <em>fire-resistance rating</em> is not required for <em>corridors</em> in <em>open parking garages</em>.</li> <li>A <em>fire-resistance rating</em> is not required for <em>corridors</em> in an occupancy in Group B that is a space requiring only a single <em>means of egress</em> complying with Section 1006.2.</li> <li><em>Corridors</em> adjacent to the <em>exterior walls</em> of buildings shall be permitted to have unprotected openings on unrated <em>exterior walls</em> where unrated walls are permitted by Table 602 and unprotected openings are permitted by Table 705.8.</li> </ol></ins></li></ul>
27+
<em>Corridors</em> shall be fire-resistance rated in accordance with Table 1020.1<ins class="diffins"> and where applicable in Section 1020.1.1</ins>. The <em>corridor</em> walls required to be fire-resistance rated shall comply with Section 708 for <em>fire partitions</em>.<br /><br class="diffmod" /><del class="diffdel">In addition, corridors in buildings of Types IIB, IIIB, and VB construction and assigned Risk Categories III and IV in Table 1604.5, other than Group I, shall have a fire resistance rating of not less than 1 hour where such buildings are any of the following:</del><br class="diffmod" /><br /><ol><li><del class="diffdel">Assigned a Seismic Design Category C or D in Table 1613.3.5(1).</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">Located in a flood hazard area established in accordance with Section 1612.3.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">Located in a </del><em class="diffmod"><del class="diffdel">hurricane-prone regions</del></em><del class="diffdel">.</del></li><del class="diffdel"> </del></ol><ul class="exception diff-list"><li class="normal"><strong>Exceptions:</strong><ol class="diffmod"><li><del class="diffdel">A </del><em class="diffmod"><del class="diffdel">fire-resistance rating</del></em><del class="diffdel"> is not required for </del><em class="diffmod"><del class="diffdel">corridors</del></em><del class="diffdel"> in an occupancy in Group E where each room that is used for instruction has not less than one door opening directly to the exterior and rooms for assembly purposes have not less than one-half of the required </del><em class="diffmod"><del class="diffdel">means of egress</del></em><del class="diffdel"> doors opening directly to the exterior. Exterior doors specified in this exception are required to be at ground level.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">A </del><em class="diffmod"><del class="diffdel">fire-resistance rating</del></em><del class="diffdel"> is not required for </del><em class="diffmod"><del class="diffdel">corridors</del></em><del class="diffdel"> contained within a </del><em class="diffmod"><del class="diffdel">dwelling unit</del></em><del class="diffdel"> or </del><em class="diffmod"><del class="diffdel">sleeping unit</del></em><del class="diffdel"> in an occupancy in Groups I-1 and R.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">A </del><em class="diffmod"><del class="diffdel">fire-resistance rating</del></em><del class="diffdel"> is not required for </del><em class="diffmod"><del class="diffdel">corridors</del></em><del class="diffdel"> in </del><em class="diffmod"><del class="diffdel">open parking garages</del></em><del class="diffdel">.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">A </del><em class="diffmod"><del class="diffdel">fire-resistance rating</del></em><del class="diffdel"> is not required for </del><em class="diffmod"><del class="diffdel">corridors</del></em><del class="diffdel"> in an occupancy in Group B that is a space requiring only a single </del><em class="diffmod"><del class="diffdel">means of egress</del></em><del class="diffdel"> complying with Section 1006.2.</del></li><del class="diffdel"> </del><li class="diffmod"><em><del class="diffdel">Corridors</del></em><del class="diffdel"> adjacent to the </del><em class="diffmod"><del class="diffdel">exterior walls</del></em><del class="diffdel"> of buildings shall be permitted to have unprotected openings on unrated </del><em class="diffmod"><del class="diffdel">exterior walls</del></em><del class="diffdel"> where unrated walls are permitted by Table 602 and unprotected openings are permitted by Table 705.8.</del></li><del class="diffdel"> </del></ol></li><li class="normal new"><ins> <ol><li>A <em>fire-resistance rating</em> is not required for <em>corridors</em> in an occupancy in Group E where each room that is used for instruction has not less than one door opening directly to the exterior and rooms for assembly purposes have not less than one-half of the required <em>means of egress</em> doors opening directly to the exterior. Exterior doors specified in this exception are required to be at ground level.</li> <li>A <em>fire-resistance rating</em> is not required for <em>corridors</em> contained within a <em>dwelling unit</em> or <em>sleeping unit</em> in an occupancy in Groups I-1 and R.</li> <li>A <em>fire-resistance rating</em> is not required for <em>corridors</em> in <em>open parking garages</em>.</li> <li>A <em>fire-resistance rating</em> is not required for <em>corridors</em> in an occupancy in Group B that is a space requiring only a single <em>means of egress</em> complying with Section 1006.2.</li> <li><em>Corridors</em> adjacent to the <em>exterior walls</em> of buildings shall be permitted to have unprotected openings on unrated <em>exterior walls</em> where unrated walls are permitted by Table 602 and unprotected openings are permitted by Table 705.8.</li> </ol></ins></li></ul>
2828
</expected>

0 commit comments

Comments
 (0)