From dc6ea3934d875ec26e7a2747db40daa4990e5302 Mon Sep 17 00:00:00 2001 From: Dylan Wagstaff Date: Mon, 12 Mar 2018 10:26:25 +1300 Subject: [PATCH] FIX backport fix for lack of HTMLPurifier breakage If HTMLPurifier is missing, a fatal error is giving for a missing class. This results in comments essentially not working. The fix is simple and has already been done in 2.0 - as the package is optional we can simply check if the classname exists before trying to use it, or do nothing. --- code/model/Comment.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/code/model/Comment.php b/code/model/Comment.php index b79282b..2bfb0cf 100755 --- a/code/model/Comment.php +++ b/code/model/Comment.php @@ -649,8 +649,10 @@ class Comment extends DataObject */ public function purifyHtml($dirtyHtml) { - $purifier = $this->getHtmlPurifierService(); - return $purifier->purify($dirtyHtml); + if ($service = $this->getHtmlPurifierService()) { + return $service->purify($dirtyHtml); + } + return $dirtyHtml; } /** @@ -658,6 +660,10 @@ class Comment extends DataObject */ public function getHtmlPurifierService() { + if (!class_exists('HTMLPurifier_Config')) { + return null; + } + $config = HTMLPurifier_Config::createDefault(); $allowedElements = $this->getOption('html_allowed_elements'); $config->set('HTML.AllowedElements', $allowedElements);