diff --git a/lib/thirdparty/Slack.class.php b/lib/thirdparty/Slack.class.php index 9264e89d..62545201 100644 --- a/lib/thirdparty/Slack.class.php +++ b/lib/thirdparty/Slack.class.php @@ -13,4 +13,12 @@ class Slack Curl::post($slackErrorNotificationUrl, ['text' => ($alert ? ' ' : '') . Request::getRelativeUri() . "\n" . $e], ['json_data' => true]); } } + + public static function slackGrin() + { + $slackErrorNotificationUrl = Config::get(Config::SLACK_ERROR_NOTIFICATION_URL); + if ($slackErrorNotificationUrl) { + Curl::post($slackErrorNotificationUrl, ['text' => '<@U1R0URBC1> Failed to parse html on ' . Request::getRelativeUri()], ['json_data' => true]); + } + } } diff --git a/view/View.class.php b/view/View.class.php index e143f5c4..a7ca448a 100644 --- a/view/View.class.php +++ b/view/View.class.php @@ -179,21 +179,25 @@ class View public static function safeExternalLinks(string $html, string $domain): string { - return $html; - - $parser = new Masterminds\HTML5(); - $dom = $parser->loadHTML($html); - $links = $dom->getElementsByTagName('body') ? - $dom->getElementsByTagName('body')[0]->getElementsByTagName('a') : - $dom->getElementsByTagName('a'); + try { + $parser = new Masterminds\HTML5(); + $dom = $parser->loadHTML($html); + $links = $dom->getElementsByTagName('body') ? + $dom->getElementsByTagName('body')[0]->getElementsByTagName('a') : + $dom->getElementsByTagName('a'); - foreach ($links as $link) { - if ($link->getAttribute('href') && static::isLinkExternal($link->getAttribute('href'), $domain)) { - $link->setAttribute('rel', "noopener noreferrer"); + foreach ($links as $link) { + if ($link->getAttribute('href') && static::isLinkExternal($link->getAttribute('href'), $domain)) { + $link->setAttribute('rel', "noopener noreferrer"); + } } - } - return $parser->saveHTML($dom); + return $parser->saveHTML($dom); + } + catch (Error $e) { + Slack::slackGrin(); + return $html; + } } public static function isLinkExternal(string $url, string $domain): bool