Skip to content

Commit 2a5a3ce

Browse files
author
Sven Hagemann
committed
Bugfix: Ignore wrapping empty nodes
Since a node with just a space in it is not interpreted as a space by a HTML parsing engine we should not insert empty tags. These seem to result from indent spacing around text being interpreted as regular spaces.
1 parent c946d79 commit 2a5a3ce

File tree

9 files changed

+21
-29
lines changed

9 files changed

+21
-29
lines changed

lib/Caxy/HtmlDiff/HtmlDiff.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ protected function processInsertOperation($operation, $cssClass)
291291
}
292292
}
293293
}
294+
294295
$this->insertTag('ins', $cssClass, $text);
295296
}
296297

@@ -544,8 +545,7 @@ protected function insertTag($tag, $cssClass, &$words)
544545
$specialCaseTagInjectionIsBefore = false;
545546

546547
if (count($nonTags) !== 0) {
547-
$text = $this->wrapText(implode('', $nonTags), $tag, $cssClass);
548-
$this->content .= $text;
548+
$this->content .= $this->wrapText(implode('', $nonTags), $tag, $cssClass);
549549
} else {
550550
$firstOrDefault = false;
551551
foreach ($this->config->getSpecialCaseOpeningTags() as $x) {
@@ -615,15 +615,12 @@ protected function checkCondition($word, $condition)
615615
return $condition == 'tag' ? $this->isTag($word) : !$this->isTag($word);
616616
}
617617

618-
/**
619-
* @param string $text
620-
* @param string $tagName
621-
* @param string $cssClass
622-
*
623-
* @return string
624-
*/
625-
protected function wrapText($text, $tagName, $cssClass)
618+
protected function wrapText(string $text, string $tagName, string $cssClass) : string
626619
{
620+
if (trim($text) === '') {
621+
return '';
622+
}
623+
627624
return sprintf('<%1$s class="%2$s">%3$s</%1$s>', $tagName, $cssClass, $text);
628625
}
629626

tests/fixtures/HtmlDiff/ICC-5136.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
</newText>
1010

1111
<expected>
12-
<p class="diffmod">Compliance with this section requires that the provisions identified in Sections R401 through R404 labeled as "mandatory" and Section R403.5.3 <ins class="diffins">shall </ins>be met. <ins class="diffins">Fenestration U-factor and SHGC shall not exceed the maximum values for the climate zone set forth in Table R402.1.2. </ins>The<ins class="diffins"> remaining components of the</ins> building thermal envelope shall <del class="diffmod">be greater than</del><ins class="diffmod">comply with either the minimum R-values</ins> or <del class="diffmod">equal to levels of efficiency and Solar Heat Gain Coefficient</del><ins class="diffmod">maximum U-factors for the climate zones specified</ins> in Table <del class="diffmod">402.1.1 or 402.1.3 of the 2009 </del><em class="diffmod"><del class="diffmod">International Energy Conservation Code</del></em><ins class="diffmod">R402.1.2 and R402.1.4</ins>.</p><ins class="diffins"> </ins><ul class="exception diff-list"><li class="normal"><strong>Exception:</strong> Supply and return ducts not completely inside the building thermal envelope shall be insulated to a minimum of R-6.</li></ul>
12+
<p class="diffmod">Compliance with this section requires that the provisions identified in Sections R401 through R404 labeled as "mandatory" and Section R403.5.3 <ins class="diffins">shall </ins>be met. <ins class="diffins">Fenestration U-factor and SHGC shall not exceed the maximum values for the climate zone set forth in Table R402.1.2. </ins>The<ins class="diffins"> remaining components of the</ins> building thermal envelope shall <del class="diffmod">be greater than</del><ins class="diffmod">comply with either the minimum R-values</ins> or <del class="diffmod">equal to levels of efficiency and Solar Heat Gain Coefficient</del><ins class="diffmod">maximum U-factors for the climate zones specified</ins> in Table <del class="diffmod">402.1.1 or 402.1.3 of the 2009 </del><em class="diffmod"><del class="diffmod">International Energy Conservation Code</del></em><ins class="diffmod">R402.1.2 and R402.1.4</ins>.</p><ul class="exception diff-list"><li class="normal"><strong>Exception:</strong> Supply and return ducts not completely inside the building thermal envelope shall be insulated to a minimum of R-6.</li></ul>
1313
</expected>

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><li class="diffmod"><ins class="diffins">Located in a flood hazard area established in accordance with Section 1612.3.</ins></li><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></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-2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
</newText>
1515

1616
<expected>
17-
<p>Air handling equipment and HVAC equipment shall be designed and installed to limit the amount of airflow that bypasses the air filters<ins class="diffins">. Filter access doors in ducts</ins> and <ins class="diffins">HVAC equipment </ins>shall <del class="diffmod">comply</del><ins class="diffmod">be designed to limit the amount of airflow that bypasses the filters. Channels, racks and other filter retaining constructions shall be sealed to the duct or housing of the HVAC equipment served by the filters. Field or shop fabricated spacers shall not be installed for the purpose of replacing the intended size filter</ins> with <del class="diffmod">the following: </del><ins class="diffmod">a smaller size filter.</ins></p><del class="diffdel"> </del><ol class="diffmod"><li><del class="diffdel">Channels, racks and other filter retaining constructions that do not seal tightly to the filter frame by means of a friction fit shall be provided with a means to seal the filter frame to the filter retaining construction.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">Where standard size filters are installed in banks of multiple filters, gaskets shall seal the gap between the frames of adjacent filters. As an alternative to gaskets, the frames of adjacent filters shall be compressed by means of spring elements that are built into the filter retaining construction.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">Channels, racks and other filter retaining constructions shall be sealed to the duct or housing of the HVAC equipment served by the filters.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">Filter access doors in ducts and HVAC equipment shall be designed to limit the amount of airflow that bypasses the filters.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">Field or shop fabricated spacers shall not be installed for the purpose of replacing the intended size filter with a smaller size filter.</del></li><del class="diffdel"> </del><li class="diffmod"><del class="diffdel">Gaskets and seals shall be provided with access for repair, maintenance and replacement.</del></li><del class="diffdel"> </del></ol>
17+
<p>Air handling equipment and HVAC equipment shall be designed and installed to limit the amount of airflow that bypasses the air filters<ins class="diffins">. Filter access doors in ducts</ins> and <ins class="diffins">HVAC equipment </ins>shall <del class="diffmod">comply</del><ins class="diffmod">be designed to limit the amount of airflow that bypasses the filters. Channels, racks and other filter retaining constructions shall be sealed to the duct or housing of the HVAC equipment served by the filters. Field or shop fabricated spacers shall not be installed for the purpose of replacing the intended size filter</ins> with <del class="diffmod">the following: </del><ins class="diffmod">a smaller size filter.</ins></p><ol class="diffmod"><li><del class="diffdel">Channels, racks and other filter retaining constructions that do not seal tightly to the filter frame by means of a friction fit shall be provided with a means to seal the filter frame to the filter retaining construction.</del></li><li class="diffmod"><del class="diffdel">Where standard size filters are installed in banks of multiple filters, gaskets shall seal the gap between the frames of adjacent filters. As an alternative to gaskets, the frames of adjacent filters shall be compressed by means of spring elements that are built into the filter retaining construction.</del></li><li class="diffmod"><del class="diffdel">Channels, racks and other filter retaining constructions shall be sealed to the duct or housing of the HVAC equipment served by the filters.</del></li><li class="diffmod"><del class="diffdel">Filter access doors in ducts and HVAC equipment shall be designed to limit the amount of airflow that bypasses the filters.</del></li><li class="diffmod"><del class="diffdel">Field or shop fabricated spacers shall not be installed for the purpose of replacing the intended size filter with a smaller size filter.</del></li><li class="diffmod"><del class="diffdel">Gaskets and seals shall be provided with access for repair, maintenance and replacement.</del></li></ol>
1818
</expected>

0 commit comments

Comments
 (0)