Skip to content

Commit

Permalink
BUGFIX Ignore invalid selectors, see #179
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Jun 19, 2015
1 parent 85d3912 commit 9621479
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Classes/Emogrifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ public function emogrify()
foreach ($this->caches[self::CACHE_KEY_CSS][$cssKey] as $value) {
// query the body for the xpath selector
$nodesMatchingCssSelectors = $xpath->query($this->translateCssToXpath($value['selector']));
// Ignore invalid selectors
if (false === $nodesMatchingCssSelectors) {
continue;
}

/** @var \DOMElement $node */
foreach ($nodesMatchingCssSelectors as $node) {
Expand Down
23 changes: 23 additions & 0 deletions Tests/Unit/EmogrifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,29 @@ public function emogrifyRemovesStyleNodes()
);
}

/**
* @test
*/
public function emogrifyIgnoreInvalidSelectors()
{
$html = $this->html5DocumentType . self::LF . '<html><style type="text/css">p{color:red;} <style data-x="1">html{cursor:text;}</style></html>';
$this->subject->setHtml($html);
$noerrors = true;
set_error_handler(function($errno, $errstr) use (&$noerrors) {
if ($errstr == 'DOMXPath::query(): Invalid expression') {
//Eat this error, see #179
return true;
}
$noerrors = false;
return true;
});
$this->subject->emogrify();
restore_error_handler();
self::assertTrue(
$noerrors
);
}

/**
* Data provider for things that should be left out when applying the CSS.
*
Expand Down

0 comments on commit 9621479

Please sign in to comment.