Skip to content

Commit

Permalink
[+]: remove unnecessary </source> closing tag
Browse files Browse the repository at this point in the history
-> fix issue #40
  • Loading branch information
voku committed Aug 30, 2019
1 parent 3ca20db commit affb1c4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/voku/helper/HtmlMin.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,13 @@ private function domNodeAttributesToString(\DOMNode $node): string
private function domNodeClosingTagOptional(\DOMNode $node): bool
{
$tag_name = $node->nodeName;

if ($node->parentNode) {
$parent_tag_name = $node->parentNode->nodeName;
} else {
$parent_tag_name = null;
}

$nextSibling = $this->getNextSiblingOfTypeDOMElement($node);

// https://html.spec.whatwg.org/multipage/syntax.html#syntax-tag-omission
Expand Down Expand Up @@ -785,9 +792,7 @@ private function domNodeClosingTagOptional(\DOMNode $node): bool
)
||
(
(
$tag_name === 'rp'
)
$tag_name === 'rp'
&&
(
$nextSibling === null
Expand Down Expand Up @@ -818,6 +823,30 @@ private function domNodeClosingTagOptional(\DOMNode $node): bool
)
)
||
(
$tag_name === 'source'
&&
(
$parent_tag_name === 'audio'
||
$parent_tag_name === 'video'
||
$parent_tag_name === 'picture'
||
$parent_tag_name === 'source'
)
&&
(
$nextSibling === null
||
(
$nextSibling instanceof \DOMElement
&&
$nextSibling->tagName === 'source'
)
)
)
||
(
(
$tag_name === 'td'
Expand Down
18 changes: 18 additions & 0 deletions tests/HtmlMinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,24 @@ public function testDisappearingWhitespaceBetweenDlAndA()
static::assertSame($expected, $htmlMin->minify($html));
}

public function testSourceNotNeeded()
{
// init
$htmlMin = new HtmlMin();

$html = "\r\n
\t<audio>\r\n
\t<source src=\"horse.ogg\" type=\"audio/ogg\">\r\n
\t<source src=\"horse.mp3\" type=\"audio/mpeg\">\r\n
\tYour browser does not support the audio element.\r\n
\t</audio>
";

$expected = '<audio><source src=horse.ogg type=audio/ogg><source src=horse.mp3 type=audio/mpeg> Your browser does not support the audio element. </audio>';

static::assertSame($expected, $htmlMin->minify($html));
}

public function testOptionsTrue()
{
// init
Expand Down

0 comments on commit affb1c4

Please sign in to comment.