diff --git a/Classes/Emogrifier.php b/Classes/Emogrifier.php index a28605f7..8fb5a0bd 100644 --- a/Classes/Emogrifier.php +++ b/Classes/Emogrifier.php @@ -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) { diff --git a/Tests/Unit/EmogrifierTest.php b/Tests/Unit/EmogrifierTest.php index 90cec121..1c913b81 100644 --- a/Tests/Unit/EmogrifierTest.php +++ b/Tests/Unit/EmogrifierTest.php @@ -620,6 +620,29 @@ public function emogrifyRemovesStyleNodes() ); } + /** + * @test + */ + public function emogrifyIgnoreInvalidSelectors() + { + $html = $this->html5DocumentType . self::LF . ''; + $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. *